-
Notifications
You must be signed in to change notification settings - Fork 15
["Discussion"] Stream TerminalOps #245
Comments
One other possibility could be to mark terminal operations with namespacing: suspend fun <A> Stream<A>drain() : Unit
suspend fun <A, B> Stream<A>.drainFold(b: B, f: (A, B) -> B) : B
suspend fun <A> Stream<A>.drainEach((A) -> Unit) : Unit
suspend fun <A> Stream<A>.drainToList() : List<A>
suspend fun <A> Stream<A>.drainToList(f: (A) -> B) : List<B>
suspend fun <A> Stream<A>.drainToSet() : Set<A>
suspend fun <A> Stream<A>.drainToSet(f: (A) -> B) : Set<B> etc. I guess the caveat of having to do Having a namespace with prefixes would mean that as the user types |
@pablisco I am not sure I 100% follow your comment. Perhaps fun <A> Stream<A>.toList(): Stream<List<A>>
suspend fun <A> TerminalOps<A>.toList(): List<A>
suspend fun <A> ResourceTerminalOps<A>.toList(): Resource<List<A>> This exposes the same functionality in 3 different ways, and we can cover the same behavior with. -fun <A> Stream<A>.toList(): Stream<List<A>>
-suspend fun <A> TerminalOps<A>.toList(): List<A>
-suspend fun <A> ResourceTerminalOps<A>.toList(): Resource<List<A>>
+suspend fun <A> Stream<A>.toList(): List<A> I believe this will less confusing, and would also be more aligned with the standard library A summary with the problematics of the original signatures:
|
This might be naive since I have not used This means we'd most likely just need one primitive which is a fold over all results/chunks a stream produces. |
You're absolutely correct @1Jajen1, that's the reason for this ticket. In practice this is not always the case tho, since most libraries expose Since our EDIT: I wanted to bring this up for discussion for those already trying Arrow Fx Streams before doing the refactor. |
What version are you currently using?
0.11.0-SNAPSHOT
What would you like to see?
Less redundant solution than
TerminalOps
, we now duplicate some operations inTerminalOps
and in theStream
API.Both offer the same behavior, with slightly different signatures. See #244
I.e.
s.foldChunk
/s.compile().foldChunks
,s.fold
/s.compile().fold
, etcDiscussed proposal with @pablisco on Slack.
Currently some operations such as
fold
,foldChunks
, etc are defined both onStream<A>
andTerminalOps<A>
.The first signatures is not properly typed since it doesn't return a
Stream<B>
but a single valueB
wrapped in aStream
, so exposing assuspend fun <A, B> Stream<A>.fold(b: B, f: (A, B) -> B): B
would be more accurate.This would allow us to remove
TerminalOps
,TerminalResourceOps
and remove duplicated operators between the 3.The text was updated successfully, but these errors were encountered: