Bob Glamm

03/21/2023, 2:54 PM
Another optics question: given:
data class Foo(x: Int)
data class Bar(y: String, foo: Foo)
data class AllTheBars(bars: List<Bar>)
is it possible get a focus (Lens or Optional) that is List<Bar> -> List<Foo>? What I'm really trying to do is come up with an Optional<AllTheBars, Foo> that focuses on a Foo that satisfies a particular predicate.
aha I see:
val focus = AllTheBars.bars compose Fold.list() compose

// then

maybeFoo: Foo? = focus.findOrNull(allTheBars) { it.x == 3 }