Skip to content

Commit

Permalink
Merge pull request #370 from CraigFe/require-map-in-io
Browse files Browse the repository at this point in the history
Require an explicit definition of IO.map
  • Loading branch information
dinosaure authored Dec 5, 2020
2 parents 194a067 + 7d33c13 commit 1cb5b02
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bench/cost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ external tick : unit -> (int64[@unboxed]) = "none" "get_tick" [@@noalloc]
module None = struct
type +'a t = 'a

let map f x = f x

let bind x f = f x

let return x = x
Expand Down
2 changes: 2 additions & 0 deletions src/async/conduit_async.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module IO = struct
type +'a t = 'a Async.Deferred.t

let map f x = Async.Deferred.map ~f x

let bind x f = Async.Deferred.bind x ~f

let return x = Async.Deferred.return x
Expand Down
2 changes: 1 addition & 1 deletion src/core/conduit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module Make (IO : IO) (Input : BUFFER) (Output : BUFFER) :

let ( >>= ) x f = IO.bind x f

let ( >>| ) x f = x >>= fun x -> return (f x)
let ( >>| ) x f = IO.map f x

let ( >>? ) x f =
x >>= function Ok x -> f x | Error err -> return (Error err)
Expand Down
2 changes: 2 additions & 0 deletions src/core/conduit_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ end
module type IO = sig
type +'a t

val map : ('a -> 'b) -> 'a t -> 'b t

val bind : 'a t -> ('a -> 'b t) -> 'b t

val return : 'a -> 'a t
Expand Down
2 changes: 2 additions & 0 deletions src/lwt/conduit_lwt.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module IO = struct
type +'a t = 'a Lwt.t

let map f x = Lwt.map f x

let bind x f = Lwt.bind x f

let return x = Lwt.return x
Expand Down
2 changes: 2 additions & 0 deletions src/mirage/conduit_mirage.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module IO = struct
type +'a t = 'a Lwt.t

let map f x = Lwt.map f x

let bind x f = Lwt.bind x f

let return x = Lwt.return x
Expand Down
2 changes: 2 additions & 0 deletions tests/flow.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Unix_scheduler = struct
type +'a t = 'a

let map f x = f x

let bind x f = f x

let return x = x
Expand Down
6 changes: 1 addition & 5 deletions tests/ping-pong/with_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ let () = Mirage_crypto_rng_unix.initialize ()

include Common.Make
(struct
type +'a t = 'a Async.Deferred.t

let bind x f = Async.Deferred.bind x ~f

let return = Async.Deferred.return
include Conduit_async.IO

let yield () = Async.Deferred.return ()
end)
Expand Down
1 change: 1 addition & 0 deletions tests/ping-pong/with_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let failwith fmt = Fmt.kstrf (fun err -> Lwt.fail (Failure err)) fmt

module Lwt = struct
include Lwt
include Conduit_lwt.IO

let yield = Lwt_unix.yield
end
Expand Down
2 changes: 2 additions & 0 deletions tests/resolvers.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Unix_scheduler = struct
type +'a t = 'a

let map f x = f x

let bind x f = f x

let return x = x
Expand Down

0 comments on commit 1cb5b02

Please sign in to comment.