Into (original) (raw)
Brian Goetz brian.goetz at oracle.com
Wed Dec 26 10:00:10 PST 2012
- Previous message: Into
- Next message: Into
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I was just translating a simple example from Uncle Bob's recent FP resolution(*). The most difficult problem given the current state of jkd8lambda was trying to print a stream...
Using StringJoiner seems like the coolest way to do this currently: stream.into(new StringJoiner(", ", "[", "]"))
Right, that's the current plan. StringJoiner implements Stream.Destination.
But how's this supposed to work without into()?
Well, that's one of the things to figure out. I think it fits pretty nicely as a mutable reduce.
make-accumulator() -> new StringJoiner() accumulate(a, e) -> a.add(e) combine(a1, a2) -> if (!a2.isEmpty) a1.addAll(a2)
This parallelizes well. The only trickiness is adding the pre/post strings, which have to be deferred to the very end. All doable.
Btw, the lack of a generic Joiner that accepts any ol' object or primitive is causing me some grief. Given a stream of ints or even Integers, having to manually map(Object::toString) seems like something StringJoiner should be doing automatically.
Yeah, it should accept Object and call toString on it. String.toString() is cheap.
- Previous message: Into
- Next message: Into
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the lambda-libs-spec-experts mailing list