@@ -49,13 +49,8 @@ module Make
4949
5050 module IO = struct
5151 module Deferred = Deferred
52- open Deferred.Infix
5352
54- type t =
55- {tries : int
56- ; client : C .t
57- ; base_url : string
58- ; config : Ezcurl_core.Config .t }
53+ type t = {tries : int ; client : C .t ; base_url : string ; config : Ezcurl_core.Config .t }
5954
6055 let get t key =
6156 let tries = t.tries and client = t.client and config = t.config in
@@ -65,7 +60,7 @@ module Make
6560 | {code; body; _} when code = 200 -> body
6661 | {code; body; _} -> raise (Request_failed (code, body))
6762
68- let size t key = try get t key >> | String. length with
63+ let size t key = try Deferred. map String. length ( get t key) with
6964 | Request_failed (404 , _ ) -> Deferred. return 0
7065 (* let size t key =
7166 let tries = t.tries and client = t.client and config = t.config in
@@ -82,25 +77,21 @@ module Make
8277 | Some l -> Deferred.return @@ int_of_string l
8378 | None ->
8479 begin try print_endline "empty content-length header";
85- get t key >>| String.length with
80+ Deferred.map String.length ( get t key) with
8681 | Request_failed (404, _) -> Deferred.return 0 end
8782 end
8883 | Ok {code; body; _} -> raise (Request_failed (code, body)) *)
8984
90- let is_member t key =
91- let + s = size t key in
92- if s > 0 then true else false
85+ let is_member t key = Deferred. map (fun s -> if s > 0 then true else false ) (size t key)
9386
9487 let get_partial_values t key ranges =
9588 let tries = t.tries and client = t.client and config = t.config and url = t.base_url ^ key in
96- let fetch range = C. get ~range ~tries ~client ~config ~url () in
97- let end_index ofs l = Printf. sprintf " %d-%d" ofs (ofs + l - 1 ) in
89+ let fetch range = C. get ~range ~tries ~client ~config ~url ()
90+ and end_index ofs l = Printf. sprintf " %d-%d" ofs (ofs + l - 1 ) in
9891 let read_range acc (ofs , len ) =
9992 let none = Printf. sprintf " %d-" ofs in
10093 let range = Option. fold ~none ~some: (end_index ofs) len in
101- let + res = fetch range in
102- let response = fold_result res in
103- response.body :: acc
94+ Deferred. map (fun r -> (fold_result r).body :: acc) (fetch range)
10495 in
10596 Deferred. fold_left read_range [] (List. rev ranges)
10697
0 commit comments