Skip to content

Commit

Permalink
add of_thunk_apply (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Nuno Monteiro <[email protected]>
  • Loading branch information
anmonteiro authored Mar 31, 2024
1 parent bbe8b51 commit eb7dbf5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions fiber/src/core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ module Var = struct
end

let of_thunk f k = f () k
let of_thunk_apply f x k = f x k

module O = struct
let ( >>> ) a b k = a (fun () -> b k)
Expand Down
10 changes: 6 additions & 4 deletions fiber/src/fiber.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type 'a fiber := 'a t
(** Create a fiber that has already terminated. *)
val return : 'a -> 'a t

(** Converts a thunk to a fiber, making sure the thunk runs in the context of
the fiber (rather than applied in the current context).
Equivalent to [(>>=) (return ())], but more explicit. *)
(** Convert a thunk to a Memo computation, making sure the thunk runs in the context of
the Memo computation rather than in the current context.
[of_thunk f] is equivalent to [return () >> f] but is more explicit. *)
val of_thunk : (unit -> 'a t) -> 'a t

(** Like [of_thunk] but accepts functions of any argument. *)
val of_thunk_apply : ('a -> 'b t) -> 'a -> 'b t

(** Fiber that never completes. *)
val never : 'a t

Expand Down

0 comments on commit eb7dbf5

Please sign in to comment.