Data.Unfoldable1.Trivial1
- Package
- purescript-trivial-unfold
- Repository
- UnrelatedString/purescript-trivial-unfold
This module provides various adapters and other such utilities
for Unfoldable1
.
#refoldMap1 Source
refoldMap1 :: forall a c. Semigroup c => (a -> c) -> Trivial1 a -> c
foldMap
specialized to Trivial1
. "Re-fold" a polymorphic Unfoldable1
.
Usually cleaner and more convenient than turbofish1
, when applicable.
#foldEnum Source
foldEnum :: forall a b. BoundedEnum a => Semigroup b => (a -> b) -> b
Map each element of a BoundedEnum
into a semigroup,
and combine the results through refold1
.
#unfoldrInf Source
unfoldrInf :: forall a b u. Unfoldable1 u => (b -> a /\ b) -> b -> u a
Unfold 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 Trivial
) or
types with truncating Unfoldable1
instances (like Maybe
).
#iterate Source
iterate :: forall a u. Unfoldable1 u => (a -> a) -> a -> u a
Create 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 Trivial
) or
types with truncating Unfoldable1
instances (like Maybe
).
#take1 Source
take1 :: forall a u. Unfoldable1 u => Int -> Trivial1 a -> u a
Keep only a strictly positive number of elements from the start.
#index1 Source
index1 :: forall a. Trivial1 a -> Int -> a
Get 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.
Re-exports from Data.Unfoldable1.Trivial1.Internal
#Trivial1 Source
newtype Trivial1 a
A 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 Trivial1
Functor Trivial1
Foldable Trivial1
Foldable1 Trivial1
The raison d'être for
Trivial1
. Allows folding polymorphicUnfoldable1
s as they generate with no explicit starting value. In particular,foldMap1
needs map only into aSemigroup
rather than aMonoid
.foldr1
uses a default implementation and may be inefficient.(Arbitrary a, Coarbitrary a) => Arbitrary (Trivial1 a)
Guaranteed finite.
Lazy (Trivial1 a)
#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 -> b
Function 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.
Wraps both arguments to
unfoldr1
in anUnfoldr1Call
.