Just package:rio

O(n) Left-justify a string to the given length, using the specified fill character on the right. Subject to fusion. Performs replacement on invalid scalar values. Examples:
>>> justifyLeft 7 'x' "foo"
"fooxxxx"
>>> justifyLeft 3 'x' "foobar"
"foobar"
O(n) Right-justify a string to the given length, using the specified fill character on the left. Performs replacement on invalid scalar values. Examples:
>>> justifyRight 7 'x' "bar"
"xxxxbar"
>>> justifyRight 3 'x' "foobar"
"foobar"
O(n) Left-justify a string to the given length, using the specified fill character on the right. Subject to fusion. Performs replacement on invalid scalar values. Examples:
justifyLeft 7 'x' "foo"    == "fooxxxx"
justifyLeft 3 'x' "foobar" == "foobar"
O(n) Right-justify a string to the given length, using the specified fill character on the left. Performs replacement on invalid scalar values. Examples:
justifyRight 7 'x' "bar"    == "xxxxbar"
justifyRight 3 'x' "foobar" == "foobar"
Adjust the value tied to a given key in this map only if it is present. Otherwise, leave the map alone.
_Just targets the value contained in a Maybe, provided it's a Just. See documentation for _Left (as these 2 are pretty similar). In particular, it can be used to write these:
  • Unsafely extracting a value from a Just:
fromJust = (^?! _Just)

  • Checking whether a value is a Just:
isJust = has _Just

  • Converting a Maybe to a list (empty or consisting of a single element):
maybeToList = (^.. _Just)

  • Gathering all Justs in a list:
catMaybes = (^.. each . _Just)

O(log n). Update a value at a specific key with the result of the provided function. When the key is not a member of the map, the original map is returned.
adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")]
adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
adjust ("new " ++) 7 empty                         == empty
O(log n). Adjust a value at a specific key. When the key is not a member of the map, the original map is returned.
let f key x = (show key) ++ ":new " ++ x
adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")]
adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")]
adjustWithKey f 7 empty                         == empty
The fromJust function extracts the element out of a Just and throws an error if its argument is Nothing.

Examples

Basic usage:
>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing
The isJust function returns True iff its argument is of the form Just _.

Examples

Basic usage:
>>> isJust (Just 3)
True
>>> isJust (Just ())
True
>>> isJust Nothing
False
Only the outer constructor is taken into consideration:
>>> isJust (Just Nothing)
True
Update the element at the specified position. If the position is out of range, the original sequence is returned. adjust can lead to poor performance and even memory leaks, because it does not force the new value before installing it in the sequence. adjust' should usually be preferred.
Update the element at the specified position. If the position is out of range, the original sequence is returned. The new value is forced before it is installed in the sequence.
adjust' f i xs =
case xs !? i of
Nothing -> xs
Just x -> let !x' = f x
in update i x' xs