Copyright | (C) Liqwid Labs 2022 |
---|---|
License | Apache 2.0 |
Maintainer | Koz Ross <[email protected]> |
Stability | Experimental |
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Various helpers for list-like structures. This module is intended to be imported qualified.
Synopsis
- preplicate :: forall (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PInteger :--> (a :--> ell a))
- pfromList :: forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). PIsListLike list a => [Term s a] -> Term s (list a)
- pmapMaybe :: forall (listO :: (S -> Type) -> S -> Type) (b :: S -> Type) (listI :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PIsListLike listI a, PIsListLike listO b) => Term s ((a :--> PMaybe b) :--> (listI a :--> listO b))
- pdeleteFirstBy :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PMaybe (list a)))
- ptryDeleteFirstBy :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> list a))
- pdeleteFirst :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). (PEq a, PIsListLike list a) => Term s (a :--> (list a :--> PMaybe (list a)))
- pfindJust :: forall (b :: S -> Type) (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s ((a :--> PMaybe b) :--> (ell a :--> PMaybe b))
- plookupAssoc :: forall (k :: S -> Type) (v :: S -> Type) (kv :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell kv, PListLike ell, PEq k) => Term s ((kv :--> k) :--> ((kv :--> v) :--> (k :--> (ell kv :--> PMaybe v))))
- phandleList :: forall (a :: S -> Type) (r :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (ell a) -> Term s r -> (Term s a -> Term s (ell a) -> Term s r) -> Term s r
- precListLookahead :: forall (a :: S -> Type) (r :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => (Term s (a :--> (ell a :--> r)) -> Term s a -> Term s a -> Term s (ell a) -> Term s r) -> (Term s a -> Term s r) -> Term s r -> Term s (ell a :--> r)
- ptryElimSingle :: forall (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (r :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => (Term s a -> Term s r) -> Term s (ell a) -> Term s r
- plistEqualsBy :: forall (list1 :: (S -> Type) -> S -> Type) (list2 :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PIsListLike list1 a, PIsListLike list2 b) => Term s ((a :--> (b :--> PBool)) :--> (list1 a :--> (list2 b :--> PBool)))
- pisSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> PBool)
- pfromSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> PMaybe a)
- ptryFromSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> a)
Construction
preplicate :: forall (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (PInteger :--> (a :--> ell a)) Source #
Given a count n
and a value x
, produces a list-like structure
containing n
copies of x
, or an empty structure if n
is non-positive.
Note
You will likely need to specify which list-like structure you want; the type
arguments for this function are optimized for use with TypeApplications
to
do exactly this task.
Since: 3.6.0
pfromList :: forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). PIsListLike list a => [Term s a] -> Term s (list a) Source #
Transformation
pmapMaybe :: forall (listO :: (S -> Type) -> S -> Type) (b :: S -> Type) (listI :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PIsListLike listI a, PIsListLike listO b) => Term s ((a :--> PMaybe b) :--> (listI a :--> listO b)) Source #
pdeleteFirstBy :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> PMaybe (list a))) Source #
O(n) . Remove the first occurance of a value that satisfies the predicate from the given list. Return nothing if said value is not in the list.
Since: 3.14.1
ptryDeleteFirstBy :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s ((a :--> PBool) :--> (list a :--> list a)) Source #
Partial version of pdeleteBy
.
Since: 3.14.1
pdeleteFirst :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). (PEq a, PIsListLike list a) => Term s (a :--> (list a :--> PMaybe (list a))) Source #
Special version of pdeleteBy
, for types with PEq
instance.
Since: 3.14.1
Search
pfindJust :: forall (b :: S -> Type) (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s ((a :--> PMaybe b) :--> (ell a :--> PMaybe b)) Source #
plookupAssoc :: forall (k :: S -> Type) (v :: S -> Type) (kv :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell kv, PListLike ell, PEq k) => Term s ((kv :--> k) :--> ((kv :--> v) :--> (k :--> (ell kv :--> PMaybe v)))) Source #
Treats a list-like structure as an assoc list. More precisely, given a
list-like structure of key-value pairs, a method of extracting the key and
the value, and a 'target' key, returns the corresponding value, or
PNothing
if there isn't one.
Note
There may be multiple mappings for a specific key; in such a situation, only the first match is returned. In general, this requires time proportional to the length of the list-like structure, as we may have to check every entry.
Since: 3.6.0
Elimination
phandleList :: forall (a :: S -> Type) (r :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => Term s (ell a) -> Term s r -> (Term s a -> Term s (ell a) -> Term s r) -> Term s r Source #
pelimList
with re-ordered arguments. Useful for cases when the 'nil
case' is simple, but the 'cons case' is complex.
Since: 3.9.0
:: forall (a :: S -> Type) (r :: S -> Type) (ell :: (S -> Type) -> S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) | |
=> (Term s (a :--> (ell a :--> r)) -> Term s a -> Term s a -> Term s (ell a) -> Term s r) | The 'two or more' case. First |
-> (Term s a -> Term s r) | The 'singleton' case, used both for true singletons and also for the end of a non-empty list-like. |
-> Term s r | The 'nil' case. |
-> Term s (ell a :--> r) |
ptryElimSingle :: forall (ell :: (S -> Type) -> S -> Type) (a :: S -> Type) (r :: S -> Type) (s :: S). (PElemConstraint ell a, PListLike ell) => (Term s a -> Term s r) -> Term s (ell a) -> Term s r Source #
Similar to pelimList
, but assumes the argument list-like is a singleton,
erroring otherwise.
Since: 3.9.0
Comparison
plistEqualsBy :: forall (list1 :: (S -> Type) -> S -> Type) (list2 :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S). (PIsListLike list1 a, PIsListLike list2 b) => Term s ((a :--> (b :--> PBool)) :--> (list1 a :--> (list2 b :--> PBool))) Source #
Check if two lists are equal. The two list types can be different. The first argument is used for equality checks.
Since: 3.14.1
Singleton
pisSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> PBool) Source #
O(1) .Return true if the given list has exactly one element.
Since: 3.14.1
pfromSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> PMaybe a) Source #
Extract a singeton value from the given list. Return nothing if the list consists of zero or more than one elements.
Since: 3.14.1
ptryFromSingleton :: forall (a :: S -> Type) (list :: (S -> Type) -> S -> Type) (s :: S). PIsListLike list a => Term s (list a :--> a) Source #
Partial version of pfromSingleton
.
Since: 3.14.1