>>> justifyLeft 7 'x' "foo" "fooxxxx"
>>> justifyLeft 3 'x' "foobar" "foobar"
>>> justifyRight 7 'x' "bar" "xxxxbar"
>>> justifyRight 3 'x' "foobar" "foobar"
justifyLeft 7 'x' "foo" == "fooxxxx" justifyLeft 3 'x' "foobar" == "foobar"
justifyRight 7 'x' "bar" == "xxxxbar" justifyRight 3 'x' "foobar" == "foobar"
fromJust = (^?! _Just)
isJust = has _Just
maybeToList = (^.. _Just)
catMaybes = (^.. each . _Just)
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
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
adjust' f i xs = case xs !? i of Nothing -> xs Just x -> let !x' = f x in update i x' xs