ocsigen / lwt

OCaml promises and concurrent I/O
https://ocsigen.org/lwt
MIT License
706 stars 172 forks source link

Lwt.npick and Lwt.nchoose return type #857

Open cyberhuman opened 3 years ago

cyberhuman commented 3 years ago

I feel since both npick and nchoose return at least one fulfilled promise, the return type must reflect this propery. Current signature:

val npick : 'a t list -> 'a list t

proposed signature:

val npick : 'a t list -> ('a * 'a list) t

Or maybe it can be separate functions not to break compatibility.

raphael-proust commented 3 years ago

It'd probably need to be a separate function for backwards compatibility.

It'd also need to be a different function to allow for the convenience of getting the results in a conveniently typed container. Specifically, it's currently possible to do things such as npick ps >>= List.iter_p h which wouldn't work with a tuple-ised non-empty list.

aantron commented 3 years ago

It'd also need to be a different function to allow for the convenience of getting the results in a conveniently typed container. Specifically, it's currently possible to do things such as npick ps >>= List.iter_p h which wouldn't work with a tuple-ised non-empty list.

Indeed, this is a drawback of using a pair. I suggest not to add this function to Lwt itself, as it adds more API noise for something that is situationally useful (even if in some sense more correct). I suggest to just recommend creating a wrapper that does this, I guess with an ugly assert false hidden inside it.