lwt icon indicating copy to clipboard operation
lwt copied to clipboard

Lwt.npick and Lwt.nchoose return type

Open cyberhuman opened this issue 3 years ago • 2 comments

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.

cyberhuman avatar May 21 '21 06:05 cyberhuman

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.

raphael-proust avatar May 25 '21 09:05 raphael-proust

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.

aantron avatar May 25 '21 12:05 aantron