Modifier and Type | Method and Description |
---|---|
static <K,V> Lens.Simple<Map<K,V>,Map<K,V>> |
asCopy()
A lens that focuses on a copy of a Map.
|
static <M extends Map<K,V>,K,V> |
asCopy(Fn1<? super Map<K,V>,? extends M> copyFn)
A lens that focuses on a copy of a
Map as a subtype M . |
static <K,V> Lens.Simple<Map<K,V>,Map<V,K>> |
inverted()
A lens that focuses on the inverse of a map (keys and values swapped).
|
static <K,V> Lens.Simple<Map<K,V>,Set<K>> |
keys()
A lens that focuses on the keys of a map.
|
static <K,V,V2> Lens.Simple<Map<K,V>,Map<K,V2>> |
mappingValues(Iso<V,V,V2,V2> iso)
A lens that focuses on a map while mapping its values with the mapping
Iso . |
static <M extends Map<K,V>,K,V> |
valueAt(Fn1<? super Map<K,V>,? extends M> copyFn,
K k)
A lens that focuses on a value at a key in a map, as a
Maybe , and produces a subtype M on
the way back out. |
static <K,V> Lens.Simple<Map<K,V>,Maybe<V>> |
valueAt(K k)
A lens that focuses on a value at a key in a map, as a
Maybe . |
static <K,V> Lens.Simple<Map<K,V>,V> |
valueAt(K k,
V defaultValue)
A lens that focuses on a value at a key in a map, falling back to
defaultV if the value is missing. |
static <K,V> Lens.Simple<Map<K,V>,Collection<V>> |
values()
A lens that focuses on the values of a map.
|
public static <M extends Map<K,V>,K,V> Lens<Map<K,V>,M,M,M> asCopy(Fn1<? super Map<K,V>,? extends M> copyFn)
Map
as a subtype M
. Useful for composition to avoid
mutating a map reference.M
- the map subtypeK
- the key typeV
- the value typecopyFn
- the copy functionpublic static <K,V> Lens.Simple<Map<K,V>,Map<K,V>> asCopy()
K
- the key typeV
- the value typepublic static <M extends Map<K,V>,K,V> Lens<Map<K,V>,M,Maybe<V>,Maybe<V>> valueAt(Fn1<? super Map<K,V>,? extends M> copyFn, K k)
Maybe
, and produces a subtype M
on
the way back out.M
- the map subtypeK
- the key typeV
- the value typecopyFn
- the copy functionk
- the key to focus onMaybe
public static <K,V> Lens.Simple<Map<K,V>,Maybe<V>> valueAt(K k)
Maybe
.K
- the key typeV
- the value typek
- the key to focus onMaybe
public static <K,V> Lens.Simple<Map<K,V>,V> valueAt(K k, V defaultValue)
defaultV
if the value is missing.
Note that this lens is NOT lawful, since "putting back what you got changes nothing" fails for any value
B
where S
is the empty map
K
- the key typeV
- the value typek
- the key to focus ondefaultValue
- the default value to use in case of a missing value at keypublic static <K,V> Lens.Simple<Map<K,V>,Set<K>> keys()
K
- the key typeV
- the value typepublic static <K,V> Lens.Simple<Map<K,V>,Collection<V>> values()
Note that this lens is NOT lawful, since "you get back what you put in" fails for all values B
that
represent a non-surjective superset of the existing values in S
.
K
- the key typeV
- the value typepublic static <K,V> Lens.Simple<Map<K,V>,Map<V,K>> inverted()
Note that this lens is very likely to NOT be lawful, since "you get back what you put in" will fail for any keys that map to the same value.
K
- the key typeV
- the value typepublic static <K,V,V2> Lens.Simple<Map<K,V>,Map<K,V2>> mappingValues(Iso<V,V,V2,V2> iso)
Iso
.
Note that for this lens to be lawful, iso
must be lawful.
K
- the key typeV
- the unfocused map value typeV2
- the focused map value typeiso
- the mapping Iso