Optics and coroutine flows question: Does this lo...
# arrow
d
Optics and coroutine flows question: Does this look like a good idea or a bad idea:
Copy code
operator fun <T, R> Flow<T>.get(lens: Lens<T, R>) = map { lens.get(it) }.distinctUntilChanged()
operator fun <T, R> Flow<T>.get(traversal: Traversal<T, R>) = map { traversal.getAll(it) }.distinctUntilChanged()

// Example usage:
    private fun <T> names(of: Optional<ProjectState, ProjectSpec>. () -> Optional<ProjectState, List<Named<T>>>) =
        projectState[ProjectState.spec.notNull.of().every.name()]

    override val availableNamedDrawings = names { drawings }
    override val availableNamedPaints = names { paints }
    override val availableNamedStrokes = names { strokes }
    override val availableNamedStyles = names { styles }