Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add [{Fiber,Memo}.of_thunk_apply] #9547

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/memo/memo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ val of_reproducible_fiber : 'a Fiber.t -> 'a t
therefore be re-executed on every build run. *)
val of_non_reproducible_fiber : 'a Fiber.t -> 'a t

(** 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

(** Combine results of two computations executed in sequence. *)
val both : 'a t -> 'b t -> ('a * 'b) t

Expand Down
1 change: 1 addition & 0 deletions vendor/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
9 changes: 6 additions & 3 deletions vendor/fiber/src/fiber.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ 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).
(** Convert a thunk to a fiber, making sure the thunk runs in the context of the fiber
rather than in the current context.

Equivalent to [(>>=) (return ())], but more explicit. *)
[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
Loading