At provides a Lens for a structure
S to focus in
A at a given index
If, for a structure
S, the focus
A can be indexed by
At can create an
Lens with focus at
S for a given index
We can use that
Lens to operate on that focus
S to get, set, and modify the focus at a given index
MapK<Int, String> can be indexed by its keys
Int, but not for every index where an entry can be found.
import arrow.core.* import arrow.optics.typeclasses.* import arrow.optics.extensions.mapk.at.* val mapAt = MapK.at<Int, String>().at(2) val map = mapOf( 1 to "one", 2 to "two", 3 to "three" ).k() mapAt.set(map, "new value".some()) // Map([(1, one), (2, new value), (3, three)])
By setting an empty value for a key, we delete that entry by removing the value.
mapAt.set(map, none()) // Map([(1, one), (3, three)])
At instances for some common datatypes in Arrow that can be indexed. You can look them up by calling
You may create instances of
At for your own datatypes which you will be able to use as demonstrated in the example above.
See Deriving and creating custom typeclass to provide your own
At instances for custom datatypes.
Do you like Arrow?✖