At provides a Lens for a structure S to focus in A at a given index I.


If for a structure S the focus A can be indexed by I then At can create an Lens with focus at S for a given index I. We can use that Lens to operate on that focus S to get, set and modify the focus at a given index I.

A MapK<Int, String> can be indexed by its keys Int but not for every index an entry can be found.

import arrow.core.*
import arrow.optics.typeclasses.*
import arrow.syntax.option.*

val mapAt =<MapKOf<Int, String>, Int, Option<String>>(2)

val map = mapOf(
            1 to "one",
            2 to "two",
            3 to "three"

mapAt.set(map, "new value".some())
// MapK(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())
// MapK(map={1=one, 3=three})

Creating your own At instances

Arrow provides 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.


The following datatypes in Arrow provide instances that adhere to the At typeclass.