view package:rio
view is a synonym for (
^.), generalised for
MonadReader (we are able to use it instead of (
^.) since
functions are instances of the
MonadReader class):
>>> view _1 (1, 2)
1
When you're using
Reader for config and your config type has
lenses generated for it, most of the time you'll be using
view
instead of
asks:
doSomething :: (MonadReader Config m) => m Int
doSomething = do
thingy <- view setting1 -- same as “asks (^. setting1)”
anotherThingy <- view setting2
...
Analyse the left end of a sequence.
Analyse the right end of a sequence.
View of the left end of a sequence.
View of the right end of a sequence.
preview is a synonym for (
^?), generalised for
MonadReader (just like
view, which is a synonym for
(
^.)).
>>> preview each [1..5]
Just 1
O(log n). Retrieves the value associated with maximal key of
the map, and the map stripped of that element, or
Nothing if
passed an empty map.
maxView (fromList [(5,"a"), (3,"b")]) == Just ("a", singleton 3 "b")
maxView empty == Nothing
O(log n). Retrieves the maximal (key,value) pair of the map,
and the map stripped of that element, or
Nothing if passed an
empty map.
maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b")
maxViewWithKey empty == Nothing
O(log n). Retrieves the value associated with minimal key of
the map, and the map stripped of that element, or
Nothing if
passed an empty map.
minView (fromList [(5,"a"), (3,"b")]) == Just ("b", singleton 5 "a")
minView empty == Nothing
O(log n). Retrieves the minimal (key,value) pair of the map,
and the map stripped of that element, or
Nothing if passed an
empty map.
minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a")
minViewWithKey empty == Nothing
O(log n). Retrieves the maximal key of the set, and the set
stripped of that element, or
Nothing if passed an empty set.
O(log n). Retrieves the minimal key of the set, and the set
stripped of that element, or
Nothing if passed an empty set.