Copyright | (c) Murdoch J. Gabbay 2020 |
---|---|
License | GPL-3 |
Maintainer | murdoch.gabbay@gmail.com |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
Helper functions
Synopsis
- rewrite :: (Typeable a, Data b) => (a -> Maybe a) -> b -> b
- repeatedly :: Eq a => (a -> a) -> a -> a
- chain :: [a -> a] -> a -> a
- toMaybe :: Bool -> a -> Maybe a
- isSubsetOf :: Eq a => [a] -> [a] -> Bool
- interleave :: [[a]] -> [a]
- safeTail :: [a] -> Maybe [a]
- safeHead :: [a] -> Maybe a
- (.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
- iota :: (HasCallStack, Foldable f) => (a -> Bool) -> f a -> a
- point :: Foldable f => (a -> Bool) -> f a -> NonEmpty a
Documentation
repeatedly :: Eq a => (a -> a) -> a -> a Source #
Apply f repeatedly until we reach a fixedpoint
toMaybe :: Bool -> a -> Maybe a Source #
Standard function, returns Just a
provided True
, and Nothing
otherwise
isSubsetOf :: Eq a => [a] -> [a] -> Bool Source #
List subset. Surely this must be in a library somewhere.
interleave :: [[a]] -> [a] Source #
Interleave a list of lists to a list
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d infixr 8 Source #
Compose functions with one argument with function with two arguments.
f .: g = \x y -> f (g x y)
.
iota :: (HasCallStack, Foldable f) => (a -> Bool) -> f a -> a Source #
Finds the unique element in a collection satisfying a predicate. Results in an error if there is no such element or if there are more than one.
>>>
iota (== 1) [1, 2, 3]
1
>>>
iota (> 1) [1, 2, 3]
*** Exception: iota: expected exactly one element to satisfy the predicate, but found at least two ...
>>>
iota (> 3) [1, 2, 3]
*** Exception: iota: expected exactly one element to satisfy the predicate, but found none ...