Data.Unconsable
- Package
- purescript-unconsable
- Repository
- 8084/purescript-unconsable
#Unconsable Source
class (Foldable t) <= Unconsable t where
The only requirement for instances of this class is that
checkUnconsableLaws
must return true
for all possible values.
checkUnconsableLaws t =
unconsableLength t == length t :: Int
Members
Instances
#unconsableLength Source
unconsableLength :: forall num a t. Unconsable t => Semiring num => t a -> num
Equivalent to length
, maybe except of stack safety.
You may want to use this function instead of length
if foldr
for
the particular data type you are using is not stack-safe.
#checkUnconsableLaws Source
checkUnconsableLaws :: forall a t. Unconsable t => t a -> Boolean
#compareLength Source
compareLength :: forall a t num. Semiring num => Ord num => Unconsable t => num -> t a -> Ordering
Given Foldable
instance F
which is also an instance of
Unconsable
, for all t :: F a
and for all n
,
compareLength n t = compare n (length t)
.
#compareLengths Source
compareLengths :: forall b a t2 t1. Unconsable t1 => Unconsable t2 => t1 a -> t2 b -> Ordering
Given Foldable
instances F1
and F2
which are also instances of
Unconsable
, for all t1 :: F1 a
and t2 :: F2 b
,
compareLengths t1 t2 = compare (length t1) (length t2)
.
#isLongerThan Source
isLongerThan :: forall b a t2 t1. Unconsable t1 => Unconsable t2 => t1 a -> t2 b -> Boolean
Checks whether the first list is longer than the second.
#isShorterThan Source
isShorterThan :: forall b a t2 t1. Unconsable t1 => Unconsable t2 => t1 a -> t2 b -> Boolean
Checks whether the first list is shorter than the second.
#isOfSameLength Source
isOfSameLength :: forall b a t2 t1. Unconsable t1 => Unconsable t2 => t1 a -> t2 b -> Boolean
Checks whether two lists are of the same length.
#longestTail Source
longestTail :: forall b a t2 t1. Unconsable t1 => Unconsable t2 => t1 a -> t2 b -> Maybe (Either (t1 a) (t2 b))
If two lists have equal lengths, returns nothing.
If one of the lists is longer than the other, cuts the longer list at the
index equal to the length of the shorter list and returns the rest of it
(wrapped in Either
, to allow passing lists of different types).
You may want to use longestTail'
instead, to avoid dealing with Either
.
longestTail [] [] == Nothing
longestTail [] [1,2] == (Just (Right [1,2]))
longestTail [1,2,3,4] [1,2] == (Just (Left [3,4]))
longestTail [1,2,3,4,5] [1,2,3,4,5] == Nothing
#longestTail' Source
longestTail' :: forall a t. Unconsable t => t a -> t a -> Maybe (t a)
Less polymorphic version of longestTail
.
#longerThan Source
longerThan :: forall a t num. Semiring num => Ord num => Unconsable t => t a -> num -> Boolean
Checks whether the list's length is strictly greater than the given number.
#shorterThan Source
shorterThan :: forall a t num. Semiring num => Ord num => Unconsable t => t a -> num -> Boolean
Checks whether the list's length is strictly less than the given number.
#hasLength Source
hasLength :: forall a t num. Semiring num => Ord num => Unconsable t => t a -> num -> Boolean
Checks whether the list's length is equal to the given number.
#isSingleton Source
isSingleton :: forall t a. Unconsable t => t a -> Boolean
Checks whether the list's length is one.
#isEmpty Source
isEmpty :: forall t a. Unconsable t => t a -> Boolean
Checks whether the list's length is zero.