I have `method(input:Set<X>):Set<X>`, ...

# announcementsg

geepawhill

04/19/2021, 1:33 PMI have *but*, the transformation can produce invalid individual values, and if that occurs the method's result will be

`method(input:Set<X>):Set<X>`

, which wants to transform each element of the (small) set, seemingly a natural fit with `.map { }`

, `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?z

Zach Klippenstein (he/him) [MOD]

04/19/2021, 1:45 PM`map`

is inline, so you can return from the outer function inside its lambda.g

geepawhill

04/19/2021, 1:55 PMSo, something like

`.map { x = transform; if(x.isbad) return emptySet(); x }`

will work?z

Zach Klippenstein (he/him) [MOD]

04/19/2021, 2:53 PMThe easiest way to find out is to try it 😉 But yes, as long as your collection is not a *not* inline).

`Sequence`

(sequence operators are g

geepawhill

04/19/2021, 5:03 PMI'll try it as soon as I get back to the 'puter. :)