Skip to content

More general join and choose operators #325

@yallop

Description

@yallop

The <&> operator has the following type:

val ( <&> ) : unit t -> unit t -> unit t

It'd be useful to have a variant that works for any promise type, returning both results, with the following type:

val ( <&> ) : 'a t -> 'b t -> ('a * 'b) t

that behaved something like this:

let (<&>) l r =
   let lv = ref None and rv = ref None in
   (    (l >>= fun v -> lv := Some v; return_unit)
    <&> (r >>= fun v -> rv := Some v; return_unit)) >|= fun () ->
   match !lv, !rv with
   | Some lv, Some rv  -> (lv, rv)
   | _ -> assert false

Similarly, the <?> operator has the following type:

val ( <?> ) : 'a t -> 'a t -> 'a t

It'd be useful to have a variant that doesn't constrain the result types to be the same, and that preserves the information about which promise delivered the result, with the following type:

val ( <?> ) : 'a t -> 'b t -> ('a, 'b) either t

that behaved something like this:

let (<?>) l r =
     map (fun l -> Left l) l
 <?> map (fun r -> Right r) r

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions