Search results

Traversable represents data structures which can be traversed, accumulating results and effects in some Applicative functor.

  • traverse runs an action for every element in a data structure, and accumulates the results.
  • sequence runs the actions contained in a data structure, and accumulates the results.
import Data.Traversable
import Data.Maybe
import Data.Int (fromNumber)

sequence [Just 1, Just 2, Just 3] == Just [1,2,3]
sequence [Nothing, Just 2, Just 3] == Nothing

traverse fromNumber [1.0, 2.0, 3.0] == Just [1,2,3]
traverse fromNumber [1.5, 2.0, 3.0] == Nothing

traverse logShow [1,2,3]
-- prints:
   1
   2
   3

traverse (\x -> [x, 0]) [1,2,3] == [[1,2,3],[1,2,0],[1,0,3],[1,0,0],[0,2,3],[0,2,0],[0,0,3],[0,0,0]]

The traverse and sequence functions should be compatible in the following sense:

  • traverse f xs = sequence (f <$> xs)
  • sequence = traverse identity

Traversable instances should also be compatible with the corresponding Foldable instances, in the following sense:

  • foldMap f = runConst <<< traverse (Const <<< f)

Default implementations are provided by the following functions:

  • traverseDefault
  • sequenceDefault
P purescript-foldable-traversable M Data.Traversable
P purescript-barbies M Data.Barbie

Traversable1 represents data structures with a minimum of one element that can be traversed, accumulating results and effects in some Applicative functor.

  • traverse1 runs an action for every element in a data structure, and accumulates the results.
  • sequence1 runs the actions contained in a data structure, and accumulates the results.

The traverse1 and sequence1 functions should be compatible in the following sense:

  • traverse1 f xs = sequence1 (f <$> xs)
  • sequence1 = traverse1 identity

Traversable1 instances should also be compatible with the corresponding Foldable1 instances, in the following sense:

  • foldMap1 f = runConst <<< traverse1 (Const <<< f)

Default implementations are provided by the following functions:

  • traverse1Default
  • sequence1Default
P purescript-foldable-traversable M Data.Semigroup.Traversable
P purescript-validation M Data.Validation.Semigroup
P purescript-validation M Data.Validation.Semiring
P purescript-functor1 M Data.Traversable1
P purescript-foldable-traversable M Data.Traversable
P purescript-ordered-collections M Data.Map.Internal
P purescript-variant M Data.Functor.Variant
P purescript-sized-vectors M Data.Vec
P purescript-sequences M Data.Sequence
P purescript-sequences M Data.Sequence.NonEmpty
P purescript-pointed M Data.Pointed.Can
P purescript-bound M Bound
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Semigroup.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-lazy M Data.Lazy
P purescript-lists M Data.List.Lazy.Types
P purescript-lists M Data.List.Types
P purescript-transformers M Control.Comonad.Env.Trans
P purescript-free M Control.Monad.Free
P purescript-variant M Data.Functor.Variant
P purescript-variant M Data.Functor.Variant
P purescript-semirings M Data.Semiring.Free
P purescript-sequences M Data.Sequence.Internal
P purescript-sequences M Data.FingerTree
P purescript-pairs M Data.Pair
P purescript-sql-squared M SqlSquared.Signature.Case
P purescript-rrb-list M RRBList.Types
P purescript-sql-squared M SqlSquared.Signature
P purescript-jack M Jack.Tree
P purescript-phylio M Bio.Phylogeny.Internal.Types
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Semigroup.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-lazy M Data.Lazy
P purescript-these M Data.These
P purescript-sequences M Data.FingerTree.Digit
P purescript-graphs M Data.Graph
P purescript-bound M Bound
P purescript-slice M Data.Slice
P purescript-slices M Data.Slice
P purescript-pointed M Data.Pointed.Smash
P purescript-pointed M Data.Pointed.Wedge