nom-0.1.0.2: Name-binding & alpha-equivalence

Copyright(c) Murdoch J. Gabbay 2020
LicenseGPL-3
Maintainermurdoch.gabbay@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Language.Nominal.Utilities

Description

Helper functions

Synopsis

Documentation

rewrite :: (Typeable a, Data b) => (a -> Maybe a) -> b -> b Source #

repeatedly :: Eq a => (a -> a) -> a -> a Source #

Apply f repeatedly until we reach a fixedpoint

chain :: [a -> a] -> a -> a Source #

Apply a list of functions in succession.

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

safeTail :: [a] -> Maybe [a] Source #

Returns Just the tail of a list if it can, and Nothing otherwise.

safeHead :: [a] -> Maybe a Source #

Returns Just the head of a list if it can, and Nothing otherwise.

(.:) :: (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
...

point :: Foldable f => (a -> Bool) -> f a -> NonEmpty a Source #

point moves the (first) element satisfying the predicate to the head of the list. Error raised if no such element found.

>>> point even [1,2,3]
2 :| [1,3]
>>> point even [1,3,5]
*** Exception: point: no such element
...