Common lenses/prisms/optionals that most projects will use.
Step into an Array at the given index.
.getOption (array 2) (Array.fromList [ 10, 11, 12, 13 ])
> Just 12
.getOption (array 8) (Array.fromList [ 10, 11, 12, 13 ])
> NothingStep into an List at the given index.
(shortcut to avoid converting a List to an Array ; if it is too slow,
consider using array and an Array instead of a List in your data)
.getOption (list 2) [ 10, 11, 12, 13 ]
> Just 12
.getOption (list 8) [ 10, 11, 12, 13 ]
> NothingIso that converts a list to an array.
.get listToArray [ 1, 2, 3, 4 ]
== Array.fromList [ 1, 2, 3, 4 ]
> True
.reverseGet listToArray (Array.fromList [ 9, 8, 7, 6 ])
== [ 9, 8, 7, 6 ]
> TrueStep into a Dict with the given key.
.getOption (dict "Tom") (Dict.fromList [ ( "Tom", "Cat" ) ])
> Just "Cat"
.getOption (dict "Jerry") (Dict.fromList [ ( "Tom", "Cat" ) ])
> NothingStep into the success value of a Result.
result.getOption (Ok 5)
> Just 5
result.getOption (Err "500")
> NothingStep into a record with an id key.
id.get { id = 1000, name = ... }
> Just 1000Since records with an id field are incredible common, this is
included for convenience. It also serves as a simple recipe for
creating record lenses.
Step into the first element of a pair.
first.get ( 'a', 'b' )
> Just 'a'Step into the second element of a pair.
second.get ( 'a', 'b' )
> Just 'b'
Step into a
Maybevalue.