This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom stream operations  RSS feed

 
Stephan van Hulst
Saloon Keeper
Posts: 7797
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Maurice,

In the past I've found it's a bit of a pain to define my own stream operations (such as zip(), or more recently, mapIf()). There was some mucking around with Spliterators and StreamSupport, and I would get it all to work, but I was never really confident about how it would hold up in a parallel or production environment. StreamSupport seems to be geared towards creating streams from custom collections, not to implement custom operations. Does your book shed more light on this matter?
 
Tom Nielson
Ranch Hand
Posts: 53
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Maurice, but just wanted to mention RxJava does have those operators with its push-based Observable<T>.
http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/


However if there is a way to make two Streams zip(), I'd be curious to see how that is done in a pull-based operation.
 
Stephan van Hulst
Saloon Keeper
Posts: 7797
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a utilities library that contains an ExtendedStream class, to which I add my custom operations. ExtendedStream implements Stream, and has a static extend(Stream) method, that simply creates an extended stream by wrapping around an existing stream. My zip operation looks something like this:



I'm not sure how to make better use of the characteristics and parallel parameters of StreamSupport.stream().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!