Module

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.

#head Source

head :: forall a. Trivial a -> Maybe a

Returns the first element, if present.

Not particularly useful, because this is just the Unfoldable instance for Maybe. Included by analogy with head1.

#tail Source

tail :: forall a u. Unfoldable u => Trivial a -> u a

Removes the first element, if present.

#last Source

last :: forall a. Trivial a -> Maybe a

Returns the last element, if present.

#init Source

init :: forall a u. Unfoldable u => Trivial a -> u a

Removes the last element, if present.

#take Source

take :: forall a u. Unfoldable u => Int -> Trivial a -> u a

Keep only a number of elements from the start.

#cons Source

cons :: forall a u. Unfoldable1 u => a -> Trivial a -> u a

Prepend 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 a

Append an element.

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.

#index Source

index :: forall a. Trivial a -> Int -> Maybe a

Get the element at the specified 0-index, or Nothing if the index is out-of-bounds.

Time complexity: O(n) in the index (calls to the generating function).

#drop Source

drop :: forall a u. Unfoldable u => Int -> Trivial a -> u a

Drop a number of elements from the start.

#refoldl Source

refoldl :: forall a c. (c -> a -> c) -> c -> Trivial a -> c

foldl specialized to Trivial. "Re-fold" a polymorphic Unfoldable. Usually cleaner and more convenient than turbofish, when applicable.

#refoldr Source

refoldr :: forall a c. (a -> c -> c) -> c -> Trivial a -> c

foldr specialized to Trivial. "Re-fold" a polymorphic Unfoldable. Usually cleaner and more convenient than turbofish, when applicable.

#refoldMap Source

refoldMap :: forall a c. Monoid c => (a -> c) -> Trivial a -> c

foldMap specialized to Trivial. "Re-fold" a polymorphic Unfoldable. Usually cleaner and more convenient than turbofish, when applicable.

#refold Source

refold :: forall a. Monoid a => Trivial a -> a

fold specialized to Trivial. "Re-fold" a polymorphic Unfoldable. Usually cleaner and more convenient than turbofish, when applicable.

#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.

Re-exports from Data.Unfoldable.Trivial.Internal

#unfoldr1Default Source

unfoldr1Default :: forall a b t. Unfoldable t => (b -> a /\ (Maybe b)) -> b -> t a

Provides a default implementation of unfoldr1 using unfoldr to satisfy the superclass bound on Unfoldable.

#turbofish Source

turbofish :: forall a b. (Trivial a -> b) -> Trivial a -> b

Function application specialized to a Trivial 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.

#trivial Source

trivial :: forall a. Trivial a -> Trivial a

Specializes its argument to Trivial.

#(::<*>) Source

Operator alias for Data.Unfoldable.Trivial.Internal.turbofish (right-associative / precedence 0)

Re-exports from Data.Unfoldable1.Trivial1

#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

#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).

#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.

#trivial1 Source

trivial1 :: forall a. Trivial1 a -> Trivial1 a

Specializes its argument to Trivial1.

#take1 Source

take1 :: forall a u. Unfoldable1 u => Int -> Trivial1 a -> u a

Keep only a strictly positive number of elements from the start.

#refoldr1 Source

refoldr1 :: forall a. (a -> a -> a) -> Trivial1 a -> a

foldr1 specialized to Trivial1. "Re-fold" a polymorphic Unfoldable1. Usually cleaner and more convenient than turbofish, when applicable.

#refoldl1 Source

refoldl1 :: forall a. (a -> a -> a) -> Trivial1 a -> a

foldl1 specialized to Trivial1. "Re-fold" a polymorphic Unfoldable1. Usually cleaner and more convenient than turbofish, when applicable.

#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.

#refold1 Source

refold1 :: forall a. Semigroup a => Trivial1 a -> a

fold specialized to Trivial1. "Re-fold" a polymorphic Unfoldable1. Usually cleaner and more convenient than turbofish1, when applicable.

#last1 Source

last1 :: forall a. Trivial1 a -> a

Returns the last element.

#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).

#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.

#head1 Source

head1 :: forall a. Trivial1 a -> a

Returns the first element.

#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.

#(::<+>) Source

Operator alias for Data.Unfoldable1.Trivial1.Internal.turbofish1 (right-associative / precedence 0)