I've never really liked the ?: ternary operator syntax, but the last time I taught CS1, I used a predominantly functional paradigm and it was natural to introduce ?: before if/else. Later on in the semester, when we had both features, we found that whenever we converted an if/else to a ?:, the code became significantly shorter and often clearer.
Very interesting, Stephan. Will try to wrap my head around that code at some point soon.
SCJP 5, SCWCD 5
Stephan van Hulst
posted 5 years ago
The ExtendedIntStream is just a class to add my custom pipeline operations to the IntStream class. I did this once before with the Stream class so I could add zip() and zipWith() operations.
ConditionallyMappingIntToObjectStream just stores a list of predicates, and an associated list of mapping functions. The elseMap() or elseFilter() method return a Stream which, when a terminal operator is invoked, will map each int using a different mapper, depending on which predicate tests as true for that element, or filters the element out if no predicates test true.
I didn't focus on code clarity, but on just proving it could work, so when I clean it up I'll repost the code.
This is my favorite show. And this is my favorite tiny ad: