Data.Unfoldable
- Package
- unfoldable
- Repository
- purerl/purescript-unfoldable
This module provides a type class for unfoldable functors, i.e.
functors which support an unfoldr operation.
This allows us to unify various operations on arrays, lists, sequences, etc.
#Unfoldable Source
class (Unfoldable1 t) <= Unfoldable t whereThis class identifies data structures which can be unfolded.
The generating function f in unfoldr f in understood as follows:
- If
f bisNothing, thenunfoldr f bshould be empty. - If
f bisJust (Tuple a b1), thenunfoldr f bshould consist ofaappended to the result ofunfoldr f b1.
Members
Instances
#replicate Source
replicate :: forall a f. Unfoldable f => Int -> a -> f aReplicate a value some natural number of times. For example:
replicate 2 "foo" == ["foo", "foo"] :: Array String
#replicateA Source
replicateA :: forall a f m. Applicative m => Unfoldable f => Traversable f => Int -> m a -> m (f a)Perform an Applicative action n times, and accumulate all the results.
#none Source
none :: forall a f. Unfoldable f => f aThe container with no elements - unfolded with zero iterations. For example:
none == [] :: forall a. Array a
#fromMaybe Source
fromMaybe :: forall a f. Unfoldable f => Maybe a -> f aConvert a Maybe to any Unfoldable like lists and arrays.
Re-exports from Data.Unfoldable1
#Unfoldable1 Source
class Unfoldable1 t whereThis class identifies non-empty data structures which can be unfolded.
The generating function f corresponds to the uncons operation of a
non-empty list or array; it always return a value, and then optionally
a value to continue unfolding from.
Members
Instances
#singleton Source
singleton :: forall a f. Unfoldable1 f => a -> f aContain a single value. For example:
singleton "foo" == NEL.singleton "foo" :: NEL.NonEmptyList String
#replicate1A Source
replicate1A :: forall a f m. Apply m => Unfoldable1 f => Traversable1 f => Int -> m a -> m (f a)Perform an Apply action n times (at least once, so values n < 1
less than one will be ignored), and accumulate the results.
#replicate1 Source
replicate1 :: forall a f. Unfoldable1 f => Int -> a -> f aReplicate a value n times. At least one value will be produced, so values
n < 1 less than one will be ignored.
replicate1 0 "foo" == NEL.singleton "foo" :: NEL.NonEmptyList String
replicate1 2 "foo" == NEL.cons "foo" (NEL.singleton "foo") :: NEL.NonEmptyList String
#range Source
range :: forall f. Unfoldable1 f => Int -> Int -> f IntCreate an Unfoldable1 containing a range of values, including both
endpoints.
range 0 0 "foo" == NEL.singleton 0 :: NEL.NonEmptyList Int
range 1 2 "foo" == NEL.cons 1 (NEL.singleton 2) :: NEL.NonEmptyList Int
range 2 0 "foo" == NEL.cons 2 (NEL.cons 1 (NEL.singleton 0)) :: NEL.NonEmptyList Int
- Modules
- Data.
Unfoldable - Data.
Unfoldable1