geepawhill
04/19/2021, 1:33 PMmethod(input:Set<X>):Set<X>
, which wants to transform each element of the (small) set, seemingly a natural fit with .map { }
, but, the transformation can produce invalid individual values, and if that occurs the method's result will be emptySet()
. In other words, under some conditions i want to short-circuit the mapping and just return the empty set. I am wondering if there is some clever stream-ish/sequence-ish way to accomplish this, or should I just go with a for-in and a result accumulator?Zach Klippenstein (he/him) [MOD]
04/19/2021, 1:45 PMmap
is inline, so you can return from the outer function inside its lambda.geepawhill
04/19/2021, 1:55 PM.map { x = transform; if(x.isbad) return emptySet(); x }
will work?Zach Klippenstein (he/him) [MOD]
04/19/2021, 2:53 PMSequence
(sequence operators are not inline).geepawhill
04/19/2021, 5:03 PM