Module

Data.Unfoldable

Package
purescript-unfoldable
Repository
purescript/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  where

This class identifies data structures which can be unfolded.

The generating function f in unfoldr f in understood as follows:

  • If f b is Nothing, then unfoldr f b should be empty.
  • If f b is Just (Tuple a b1), then unfoldr f b should consist of a appended to the result of unfoldr f b1.

Members

Instances

#replicate Source

replicate :: forall f a. Unfoldable f => Int -> a -> f a

Replicate a value some natural number of times. For example:

replicate 2 "foo" == ["foo", "foo"] :: Array String

#replicateA Source

replicateA :: forall m f a. 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 f a. Unfoldable f => f a

The container with no elements - unfolded with zero iterations. For example:

none == [] :: forall a. Array a

#fromMaybe Source

fromMaybe :: forall f a. Unfoldable f => Maybe a -> f a

Convert a Maybe to any Unfoldable like lists and arrays.

Re-exports from Data.Unfoldable1

#Unfoldable1 Source

class Unfoldable1 t  where

This 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 f a. Unfoldable1 f => a -> f a

Contain a single value. For example:

singleton "foo" == NEL.singleton "foo" :: NEL.NonEmptyList String

#replicate1A Source

replicate1A :: forall m f a. 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 f a. Unfoldable1 f => Int -> a -> f a

Replicate 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 Int

Create 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