Skip to content

Latest commit

 

History

History
38 lines (25 loc) · 1.08 KB

README.md

File metadata and controls

38 lines (25 loc) · 1.08 KB
layout title permalink
docs-optics
Each
/optics/each/

Each

Each provides a [Traversal]({{ '/optics/traversal/' | relative_url }}) that can focus into a structure S to see all its foci A.

Example

Each can easily be created given a Traverse instance.

import arrow.core.*
import arrow.optics.*
import arrow.optics.typeclasses.*
import arrow.core.extensions.listk.traverse.*

val each: Each<ListKOf<Int>, Int> = Each.fromTraverse(ListK.traverse())

val listTraversal: Traversal<ListKOf<Int>, Int> = each.each()

listTraversal.lastOption(listOf(1, 2, 3).k())
listTraversal.lastOption(ListK.empty())

Creating your own Each instances

Arrow provides Each instances for some common datatypes in Arrow. You can look them up by calling Each.each().

You may create instances of Each for your own datatypes, which you will be able to use as demonstrated in the example above.

See [Deriving and creating custom typeclass]({{ '/patterns/glossary' | relative_url }}) to provide your own Each instances for custom datatypes.