Created
July 15, 2016 18:57
-
-
Save rgrinberg/a9cdecb05a32419df943be5b3d069f65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type csv | |
(* Note that all of the types here are context passing types *) | |
val ingest : Time.t -> csv -> Client_dep.t Or_error.t Context.t list | |
(* This step has to be compounded unfortunately. | |
This is b/c: | |
- you need the jc to apply client hacks (for multicare) | |
- to apply client hacks, you only do it for specific jc's | |
*) | |
val client_hacks : Bling.t -> Client_dep.t -> job_category * Client_indep.t | |
val split : Client_indep.t -> Hire_or_term.t list Or_error.t | |
val to_entities : Hire_or_term.t -> Entity_pack.t Or_error.t | |
val insert : Pgocaml_async.t -> Entity_pack.t -> Deferred.Or_error.t | |
(* The way our context is threaded goes like this: | |
* wrap a value with a context | |
* pass the value inside to a function | |
if the function: | |
* always succeeds, this is the equivalent of Context.map | |
* returns Or_error, in this case if it's an error we toss the value, | |
*) | |
let all () = | |
let client = failwith "" in | |
let context = ingest time csv in | |
let bling = find_bling client in | |
let v = context.Context.value in | |
(* Entity_pack.t Or_error.t Context.t list *) | |
let packs = | |
List.concat_map ~f:(Context.map ~f:(fun x -> | |
x >>= fun client_dep -> | |
client_hacks bling client_dep >>= fun client_indep -> | |
split client_indep >>= fun hire_terms -> | |
hire_terms |> Or_error.List.map ~f:to_entities | |
)) | |
|> Deferred.List.map (Context.map ~f:(fun ep -> | |
insert dbh ep | |
)) >>= fun all -> | |
let eeids = collect_eeids all in | |
insert_tps eeids >>= fun errors -> | |
let all_errors = (extract_errors all) @ errors in | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment