Permalink
Browse files

Convert to Batteries 2.0

  • Loading branch information...
VictorNicollet committed Jul 19, 2013
1 parent 329f047 commit 7d4e53f10a7b437be25414f2d1c4b36da8317813
@@ -133,7 +133,7 @@ struct
| None -> None
let progress id =
- Run.map (BatOption.bind compute_progress) (Tbl.get id)
+ Run.map (flip BatOption.bind compute_progress) (Tbl.get id)
let delete id = Tbl.delete id
@@ -144,7 +144,7 @@ struct
if data # finished then Some (data # data) else None
let download id =
- Run.map (BatOption.bind if_finished) (Tbl.get id)
+ Run.map (flip BatOption.bind if_finished) (Tbl.get id)
let get_state = function
| None -> `Missing
@@ -165,7 +165,7 @@ struct
let recent age limit =
let! time = ohmctx (#time) in
- Run.map (List.map (#id |- MyId.of_id))
+ Run.map (List.map (#id %> MyId.of_id))
(LastTouchedView.query ~startkey:(time -. age) ~descending:true ~limit ())
let sweep ~count ~age =
@@ -371,7 +371,7 @@ module Make = functor(C:CONFIG) -> struct
let doExpressCheckoutPayment id ~config =
let! payment = ohm_req_or (return None) $ get id in
- let payer_opt = payment.Payment.payer |> BatOption.bind (fun payer -> payer # id) in
+ let payer_opt = payment.Payment.payer |> flip BatOption.bind (fun payer -> payer # id) in
match payer_opt with None -> return None | Some payerid ->
@@ -81,7 +81,7 @@ module Make = functor(R:REGISTRY_CONFIG) -> struct
let key = R.Id.to_id id in
let id = merge id prop in
Tbl.transact id begin fun oline ->
- let oelt = BatOption.bind (#value |- prop.fmt.Fmt.of_json) oline in
+ let oelt = BatOption.bind oline (#value %> prop.fmt.Fmt.of_json) in
let! elt = ohm (f oelt) in
let line = object
method value = prop.fmt.Fmt.to_json elt
@@ -131,8 +131,8 @@ module Make = functor(T:TABULAR) -> struct
(* Data structure transforms *)
let canonical_sources columns source filter =
- let cell_sources = List.map (T.evaluator_of_column |- T.sources_of_evaluator) columns in
- let filter_sources = BatOption.(default [] $ map T.sources_of_evaluator filter) in
+ let cell_sources = List.map (T.evaluator_of_column %> T.sources_of_evaluator) columns in
+ let filter_sources = BatOption.default [] $ BatOption.map T.sources_of_evaluator filter in
BatList.sort_unique compare $ List.concat (filter_sources :: [source] :: cell_sources)
let canonical_columns columns =
@@ -490,7 +490,7 @@ module Make = functor(T:TABULAR) -> struct
let update_all key =
let! lists = ohm $ decay (KeyView.by_key (Key.to_id key)) in
- let lists = List.map (#value |- ListId.of_id) lists in
+ let lists = List.map (#value %> ListId.of_id) lists in
let schedule_list lid =
decay $ ListTable.transact lid begin function
@@ -59,7 +59,7 @@ module Make = functor (DB:CouchDB.DATABASE) -> struct
let reverse id =
let! list = ohm $ Reverse.by_key id in
- return $ List.map (#id |- Id.str) list
+ return $ List.map (#id %> Id.str) list
let lock value id =
let update value =
@@ -363,7 +363,7 @@ module Make = functor (Versioned:VERSIONED) -> struct
~startkey:(id,0.0) ~endkey:(id,max_float) ()
in
let remove_version vid = VersionTable.delete vid in
- let! _ = ohm $ Run.list_iter (#id |- VersionId.of_id |- remove_version) versions in
+ let! _ = ohm $ Run.list_iter (#id %> VersionId.of_id %> remove_version) versions in
(* Remove the object itself *)
ObjectTable.delete oid
View
@@ -12,7 +12,7 @@ let here = ""
type ('ctx,'seed,'result) template = {
template : ('ctx,Json_type.t) Run.t ;
init : 'seed -> ('ctx,Json_type.t) Run.t ;
- parse : Json_type.t -> field -> ('ctx,('result,(field * string) list) BatStd.result) Run.t ;
+ parse : Json_type.t -> field -> ('ctx,('result,(field * string) list) result) Run.t ;
}
let seed_map f t =
@@ -482,7 +482,7 @@ let from_post post =
with _ -> empty
type ('ctx,'result) form = {
- result : ('ctx,('result, (field * string) list) BatStd.result) Run.t ;
+ result : ('ctx,('result, (field * string) list) result) Run.t ;
errors : (field * string) list ;
config : ('ctx,Json.t) Run.t ;
data : ('ctx,Json.t) Run.t
View
@@ -65,7 +65,7 @@ val string :
?label:(selector * ('ctx,string) Ohm.Run.t) ->
?error:selector ->
('seed -> ('ctx,string) Ohm.Run.t) ->
- (field -> string -> ('ctx,('result,field * string) BatStd.result) Ohm.Run.t) ->
+ (field -> string -> ('ctx,('result,field * string) BatPervasives.result) Ohm.Run.t) ->
('ctx,'seed,'result) template
(** A single JSON field.
@@ -91,7 +91,7 @@ val json :
?label:(selector * ('ctx,string) Ohm.Run.t) ->
?error:selector ->
('seed -> ('ctx,Ohm.Json.t) Ohm.Run.t) ->
- (field -> Ohm.Json.t -> ('ctx,('result,field * string) BatStd.result) Ohm.Run.t) ->
+ (field -> Ohm.Json.t -> ('ctx,('result,field * string) BatPervasives.result) Ohm.Run.t) ->
('ctx,'seed,'result) template
(** A JSON selector/autocomplete field.
@@ -128,7 +128,7 @@ val select :
|`Dynamic of string
|`Both of ('data * string * ('ctx,Ohm.Html.writer) Ohm.Run.t option) list * string] ->
('seed -> ('ctx,'data option) Ohm.Run.t) ->
- (field -> 'data option -> ('ctx,('result,field * string) BatStd.result) Ohm.Run.t) ->
+ (field -> 'data option -> ('ctx,('result,field * string) BatPervasives.result) Ohm.Run.t) ->
('ctx,'seed,'result) template
@@ -163,7 +163,7 @@ val choice :
source:('data * ('ctx,Ohm.Html.writer) Ohm.Run.t) list ->
multiple:bool ->
('seed -> ('ctx,'data list) Ohm.Run.t) ->
- (field -> 'data list -> ('ctx,('result,field * string) BatStd.result) Ohm.Run.t) ->
+ (field -> 'data list -> ('ctx,('result,field * string) BatPervasives.result) Ohm.Run.t) ->
('ctx,'seed,'result) template
@@ -259,7 +259,7 @@ val end_object :
(** Convenience result parsing function. [keep field value] always
evaluates to [return (Ok value)]. *)
-val keep : field -> 'data -> ('ctx,('data,field * string) BatStd.result) Ohm.Run.t
+val keep : field -> 'data -> ('ctx,('data,field * string) BatPervasives.result) Ohm.Run.t
(** Convenience result parsing function. [keep error field value] either
evaluates to [return (Ok value)] if value is a non-empty string or to
@@ -268,15 +268,15 @@ val required :
('ctx,string) Ohm.Run.t
-> field
-> string
- -> ('ctx,(string,field * string) BatStd.result) Ohm.Run.t
+ -> ('ctx,(string,field * string) BatPervasives.result) Ohm.Run.t
(** Convenience result for adding the field to the returned value. This helps
when post-processing is required (such as when checking two fields together)
and the field needs to be available to add the error.
*)
val postpone :
- (field -> 'data -> ('ctx,('data,field * string) BatStd.result) Ohm.Run.t)
- -> (field -> 'data -> ('ctx,('data * field,field * string) BatStd.result) Ohm.Run.t)
+ (field -> 'data -> ('ctx,('data,field * string) BatPervasives.result) Ohm.Run.t)
+ -> (field -> 'data -> ('ctx,('data * field,field * string) BatPervasives.result) Ohm.Run.t)
(** Provides a source of data for initializing a form during construction. *)
type 'seed source
@@ -328,10 +328,10 @@ val has_errors : ('ctx,'result) form -> bool
(** Extract the form data as a result type. This uses the parsing functions provided in the
template. Usually, the result type is either a variant that can represent a correct value
- OR a list of errors, or a function that returns such a variant. Use of BatStd.result is
+ OR a list of errors, or a function that returns such a variant. Use of BatPervasives.result is
suggested.
*)
-val result : ('ctx,'result) form -> ('ctx,('result, (field * string) list) BatStd.result) Ohm.Run.t
+val result : ('ctx,'result) form -> ('ctx,('result, (field * string) list) BatPervasives.result) Ohm.Run.t
(** Convenience utility functions. *)
module Convenience : sig
@@ -349,7 +349,7 @@ module Convenience : sig
-> ('ctx,string) Ohm.Run.t
-> field
-> string
- -> ('ctx,(string,field * string) BatStd.result) Ohm.Run.t
+ -> ('ctx,(string,field * string) BatPervasives.result) Ohm.Run.t
end
@@ -366,27 +366,27 @@ module Skin : sig
val text :
label:('c,string) Ohm.Run.t
-> ('s -> ('c,string) Ohm.Run.t)
- -> (field -> string -> ('c,('r,field * string) BatStd.result) Ohm.Run.t)
+ -> (field -> string -> ('c,('r,field * string) BatPervasives.result) Ohm.Run.t)
-> ('c,'s,'r) template
(** A [type="text"] input field with [class="-wide"] *)
val widetext :
label:('c,string) Ohm.Run.t
-> ('s -> ('c,string) Ohm.Run.t)
- -> (field -> string -> ('c,('r,field * string) BatStd.result) Ohm.Run.t)
+ -> (field -> string -> ('c,('r,field * string) BatPervasives.result) Ohm.Run.t)
-> ('c,'s,'r) template
(** A [textarea] field. *)
val textarea :
label:('c,string) Ohm.Run.t
-> ('s -> ('c,string) Ohm.Run.t)
- -> (field -> string -> ('c,('r,field * string) BatStd.result) Ohm.Run.t)
+ -> (field -> string -> ('c,('r,field * string) BatPervasives.result) Ohm.Run.t)
-> ('c,'s,'r) template
(** A [type="password"] input field. *)
val password :
label:('c,string) Ohm.Run.t
- -> (field -> string -> ('c,('r,field * string) BatStd.result) Ohm.Run.t)
+ -> (field -> string -> ('c,('r,field * string) BatPervasives.result) Ohm.Run.t)
-> ('c,'s,'r) template
(** A list of radio-buttons. *)
@@ -396,7 +396,7 @@ module Skin : sig
format:'data Ohm.Fmt.fmt ->
source:('data * ('ctx,Ohm.Html.writer) Ohm.Run.t) list ->
('seed -> ('ctx,'data option) Ohm.Run.t) ->
- (field -> 'data option -> ('ctx,('result,field * string) BatStd.result) Ohm.Run.t) ->
+ (field -> 'data option -> ('ctx,('result,field * string) BatPervasives.result) Ohm.Run.t) ->
('ctx,'seed,'result) template
(** An optional field containing a sub-form *)
@@ -25,7 +25,7 @@ type ('key,'data) prev_next = <
next : ('key,'data) page option ;
>
-type ('key,'data) t = ('key,'data) node list * ('key, ('key,'data) node) BatPMap.t
+type ('key,'data) t = ('key,'data) node list * ('key, ('key,'data) node) BatMap.t
let no_url _ = None
@@ -82,20 +82,20 @@ let make list =
) in
Array.to_list nodes,
- Array.fold_left (fun map item -> BatPMap.add (item # page # key) item map) BatPMap.empty nodes
+ Array.fold_left (fun map item -> BatMap.add (item # page # key) item map) BatMap.empty nodes
let full_list ?(url=no_url) (t,_) =
- List.map (#page |- with_url url) t
+ List.map (#page %> with_url url) t
let list ?(url=no_url) key (t,m) =
- if BatPMap.mem key m then
- Some (List.map (#page |- selected url key) t)
+ if BatMap.mem key m then
+ Some (List.map (#page %> selected url key) t)
else
None
let prev_next ?(url=no_url) key (_,m) =
try
- let node = BatPMap.find key m in
+ let node = BatMap.find key m in
Some (object
method prev = BatOption.map (with_url url) (node # prev)
method next = BatOption.map (with_url url) (node # next)
View
@@ -18,7 +18,7 @@ type page = <
json : renaming -> (string * Json.t) list ;
>
type item = [ `Page of page | `File of string ]
-type site = (string,item) BatPMap.t
+type site = (string,item) BatMap.t
type ('server,'site) rec_pageinfo = <
body : Ohm.Html.writer ;
@@ -164,31 +164,31 @@ let info_builder key page title public url exported req =
let export ?(rename=canonical) ?(render=default_render) ?(public="/") ~server ~title site =
let files, endpoints, pages, definitions =
- BatPMap.foldi begin fun key item (files, endpoints, pages, definitions) ->
+ BatMap.foldi begin fun key item (files, endpoints, pages, definitions) ->
match item with
- | `File path -> BatPMap.add key path files, endpoints, pages, definitions
+ | `File path -> BatMap.add key path files, endpoints, pages, definitions
| `Page page ->
try
let endpoint, define = Action.declare server (rename key) Action.Args.none in
let info = info_builder key page title public in
files,
- BatPMap.add key endpoint endpoints,
- BatPMap.add key info pages,
+ BatMap.add key endpoint endpoints,
+ BatMap.add key info pages,
(define,page,key,info) :: definitions
with Private ->
files, endpoints, pages, definitions
- end site (BatPMap.empty, BatPMap.empty, BatPMap.empty, [])
+ end site (BatMap.empty, BatMap.empty, BatMap.empty, [])
in
let url server key =
- try Some (Action.url (BatPMap.find key endpoints) server ())
+ try Some (Action.url (BatMap.find key endpoints) server ())
with Not_found ->
- try Some (public ^ BatPMap.find key files)
+ try Some (public ^ BatMap.find key files)
with Not_found -> None
in
let get_page exported req key =
- try Some (BatPMap.find key pages url exported req)
+ try Some (BatMap.find key pages url exported req)
with Not_found -> None
in
View
@@ -45,7 +45,7 @@ type item = [ `Page of page | `File of string ]
(** The type of a static site - it maps the key (which is the relative path of an
item within the /static directory) to its contents.
*)
-type site = (string,item) BatPMap.t
+type site = (string,item) BatMap.t
(** A module for working on exported sites. *)
module Exported : sig
View
@@ -100,7 +100,7 @@ let rec directory path =
) contents
in
- List.concat (List.map (Filename.concat path |- directory) valid)
+ List.concat (List.map (Filename.concat path %> directory) valid)
| _ -> []
@@ -154,7 +154,7 @@ let generate ?name root =
let mlbuf = Buffer.create 1024 in
Buffer.add_string mlbuf "(* This file was generated by plugin ohmStatic *)\n" ;
- Buffer.add_string mlbuf "let site = BatPMap.of_enum (BatList.enum [\n" ;
+ Buffer.add_string mlbuf "let site = BatMap.of_enum (BatList.enum [\n" ;
List.iter (fun (path,contents) ->

0 comments on commit 7d4e53f

Please sign in to comment.