arturopala/elm-monocle/1.4.0

NOTE: this package is not compatible with Elm 0.19.1

Monocle.Common

Common lenses/prisms/optionals that most projects will use.

(=>) : Optional a b -> Optional b c -> Optional a c

Convenient infix operator for composing optionals.

.getOption (maybe => array 2) (Just [10..15])

12

maybe : Optional (Maybe a) a

Step into a Maybe value.

maybe.set 5 Nothing
> Just 5
array : Int -> Optional (Array a) a

Step into an Array at the given index.

array.getOption 2 (Array.fromList [10..15])
> Just 12


array.getOption 8 (Array.fromList [10..15])
> Nothing
dict : comparable -> Optional (Dict comparable v) v

Step into a Dict with the given key.

dict.getOption "Tom" (Dict.fromList [("Tom","Cat")])
> Just "Cat"


dict.getOption "Jerry" (Dict.fromList [("Tom","Cat")])
> Nothing
result : Optional (Result e a) a

Step into the success value of a Result.

result.getOption (Ok 5)
> Just 5


result.getOption (Err "500")
> Nothing
id : Lens { a | id : b } b

Step into a record with an id key.

id.get {id = 1000, name = ...}
> Just 1000

Since records with an id field are incredible common, this is included for convenience. It also serves as a simple recipe for creating record lenses.

first : Lens ( a, b ) a

Step into the first element of a pair.

first.get ('a', 'b')
> Just 'a'
second : Lens ( a, b ) b

Step into the second element of a pair.

second.get ('a', 'b')
> Just 'b'