Data.Unfoldable.Trivial
- Package
- purescript-trivial-unfold
- Repository
- UnrelatedString/purescript-trivial-unfold
This module provides various adapters and other such utilities
for Unfoldable1 and Unfoldable.
#tail Source
tail :: forall a u. Unfoldable u => Trivial a -> u aRemoves the first element, if present.
#init Source
init :: forall a u. Unfoldable u => Trivial a -> u aRemoves the last element, if present.
#take Source
take :: forall a u. Unfoldable u => Int -> Trivial a -> u aKeep only a number of elements from the start.
#cons Source
cons :: forall a u. Unfoldable1 u => a -> Trivial a -> u aPrepend an element.
Do not use this to create a data structure. Please use Data.List.Lazy instead.
#snoc Source
snoc :: forall a u. Unfoldable1 u => Trivial a -> a -> u aAppend an element.
Do not use this to create a data structure. Please use Data.List.Lazy instead.
#append' Source
append' :: forall a u. Unfoldable u => Trivial a -> Trivial a -> u aConcatenate two Unfoldables.
Do not use this to create a data structure. Please use Data.List.Lazy instead.
#uncons Source
uncons :: forall a u. Unfoldable u => Trivial a -> Maybe (a /\ (u a))Returns the first element and a new Unfoldable generating the remaining elements,
or Nothing if there are no elements.
#drop Source
drop :: forall a u. Unfoldable u => Int -> Trivial a -> u aDrop a number of elements from the start.
#emptyIfNone Source
emptyIfNone :: forall a f u. Alternative f => Unfoldable1 u => Trivial a -> u (f a)Lift the elements of an Unfoldable into an Alternative (such as Maybe),
filling in a single empty if there are no elements.
If you more generally want to augment an Unfoldable1 with emptiness,
you almost certainly should use MaybeEmpty instead.
#catMaybes Source
catMaybes :: forall u a. Unfoldable u => Trivial (Maybe a) -> u aUnwrap Justs and discard Nothings.
Re-exports from Data.Unfoldable.Trivial.Internal
#unfoldr1Default Source
unfoldr1Default :: forall a b t. Unfoldable t => (b -> a /\ (Maybe b)) -> b -> t aProvides a default implementation of unfoldr1 using unfoldr to satisfy
the superclass bound on Unfoldable.
#(::<*>) Source
Operator alias for Data.Unfoldable.Trivial.Internal.turbofish (right-associative / precedence 0)
Re-exports from Data.Unfoldable1.Trivial1
#Trivial1 Source
newtype Trivial1 aA type wrapping unfoldr1 calls, existentially quantified over the seed type
so that it can be ignored in the type constructor. Its Unfoldable1 instance
means that it can directly be constructed by calling unfoldr1.
Instances
Unfoldable1 Trivial1Functor Trivial1Invariant Trivial1Foldable Trivial1Foldable1 Trivial1The raison d'être for
Trivial1. Allows folding polymorphicUnfoldable1s as they generate with no explicit starting value. In particular,foldMap1needs map only into aSemigrouprather than aMonoid.foldr1uses a default implementation and may be inefficient.(Arbitrary a, Coarbitrary a) => Arbitrary (Trivial1 a)Guaranteed finite.
Lazy (Trivial1 a)Semigroup (Trivial1 a)Concatenation.
Do not use this to create a data structure. Please use Data.List.Lazy instead.
Apply Trivial1Zipwith; chosen over the
Monad-compatible nondet choice used forArrayetc. because that would require effectively forcing one argument and either re-evaluating it constantly or storing its elements in a real container at which point please please please just do that without usingTrivial1. Length is the minimum of the arguments' lengths.Applicative Trivial1Infinitely cycles to satisfy the Applicative laws! If you just want one element, use
singletoninstead.Alt Trivial1Not concatenation!
(<|>)clobbers a prefix of the right argument of the length of the left for consistency withAlternative Trivial, althoughTrivial1itself fundamentally lacks aPlusinstance.(Eq a) => Eq (Trivial1 a)Does not and cannot memoize the values being produced to compare. Please consider using Data.List.Lazy or your strict container of choice instead if you have any intention of using this for anything else.
(Ord a) => Ord (Trivial1 a)Eq1 Trivial1Ord1 Trivial1(Show a) => Show (Trivial1 a)
#unfoldrInf Source
unfoldrInf :: forall a b u. Unfoldable1 u => (b -> a /\ b) -> b -> u aUnfold an infinite Unfoldable1.
Analogous to unfold1 and unfold, but with no way to signal termination;
unfoldInf f b consists of fst $ f b appended to unfoldInf f $ snd $ f b.
This should only be used to produce either lazy types (like lazy Lists) or
types with truncating Unfoldable1 instances (like Maybe).
#uncons1 Source
uncons1 :: forall a u. Unfoldable u => Trivial1 a -> a /\ (u a)Returns the first element, and an Unfoldable of the remaining elements.
#turbofish1 Source
turbofish1 :: forall a b. (Trivial1 a -> b) -> Trivial1 a -> bFunction application specialized to a Trivial1 argument,
at the same precedence as ($).
Inspired by the Rust syntax of the same name, often used in the analogous context of collecting from an iterator.
#take1 Source
take1 :: forall a u. Unfoldable1 u => Int -> Trivial1 a -> u aKeep only a strictly positive number of elements from the start.
#repeat Source
repeat :: forall a u. Unfoldable1 u => a -> u aCreate an infinite Unfoldable1 by repeating a single element.
#refoldMap1 Source
refoldMap1 :: forall a c. Semigroup c => (a -> c) -> Trivial1 a -> cfoldMap specialized to Trivial1. "Re-fold" a polymorphic Unfoldable1.
Usually cleaner and more convenient than turbofish1, when applicable.
#iterate Source
iterate :: forall a u. Unfoldable1 u => (a -> a) -> a -> u aCreate an infinite Unfoldable1 by repeated application of a function to a seed value.
Analogous to iterateN, but with no iteration limit.
This should only be used to produce either lazy types (like lazy Lists) or
types with truncating Unfoldable1 instances (like Maybe).
#index1 Source
index1 :: forall a. Trivial1 a -> Int -> aGet the element at the specified modular 0-index, i.e. the element at that 0-index in the elements infinitely extended left and right.
Will loop infinitely if given an infinite Unfoldable1 and a negative index.
Will not loop infinitely if given an infinite Unfoldable1 and a nonnegative index;
computes the length for itself as it iterates. Iterates twice when resolving an out of
bounds index; does not store any intermediate results. In general, this function is
not supposed to be used for modular indexing, because modular indexing just happens
to be a simple and sensible way to guarantee an output, and there's no point in this
existing without a guaranteed output (just use index).
If you want modular indexing for the mod, please use an actual container.
#foldEnum Source
foldEnum :: forall a b. BoundedEnum a => Semigroup b => (a -> b) -> bMap each element of a BoundedEnum into a semigroup,
and combine the results through refold1.
#append1' Source
append1' :: forall a u. Unfoldable1 u => Trivial a -> Trivial1 a -> u aConcatenate a possibly-empty Unfoldable with an Unfoldable1.
Do not use this to create a data structure. Please use Data.List.Lazy instead.
Wraps both arguments to
unfoldr1in anUnfoldr1Call.