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
P purescript-foldable-traversable M Data.Traversable
P purescript-foreign-object M Foreign.Object
P purescript-free M Control.Comonad.Cofree
P purescript-profunctor-lenses M Data.Lens.Internal.Tagged
P purescript-tagged M Data.Functor.Tagged
P purescript-concur-core M Control.Cofree
P purescript-web3 M Network.Ethereum.Web3.Solidity.Vector
P purescript-ejson M Data.Json.Extended.Signature.Core
P purescript-transformerless M Control.Monad.Transformerless.Except
P purescript-matrices M Matrix
P purescript-moldy M Data.Moldy
P purescript-result M Data.Result
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-lists M Data.List.ZipList
P purescript-catenable-lists M Data.CatList
P purescript-freet M Control.Comonad.Cofree.Trans
P purescript-unordered-collections M Data.HashMap
P purescript-ejson M Data.Json.Extended.Cursor
P purescript-transformation-matrix M Data.TransformationMatrix.Vector2
P purescript-transformation-matrix M Data.TransformationMatrix.Vector3
P purescript-veither M Data.Veither
P purescript-vexflow M Vex.Builder
P purescript-sql-squared M SqlSquared.Signature.GroupBy
P purescript-unordered-containers M Data.HashMap
P purescript-sql-squared M SqlSquared.Signature.OrderBy
P purescript-liminal M Data.Vector.Vector4
P purescript-liminal M Data.Vector.Vector8
P purescript-foldable-traversable M Data.Traversable
P purescript-foldable-traversable M Data.Semigroup.Traversable
P purescript-foldable-traversable M Data.Traversable
P purescript-nonempty M Data.NonEmpty
P purescript-datetime M Data.Interval
P purescript-catenable-lists M Data.CatQueue
P purescript-free M Data.Coyoneda
P purescript-variant M Data.Functor.Variant
P purescript-indexed-nonempty M Data.NonEmpty.Indexed
P purescript-ejson M Data.Json.Extended.Signature.Core
P purescript-optional M Data.Optional
P purescript-sql-squared M SqlSquared.Signature.Relation
P purescript-sql-squared M SqlSquared.Signature
P purescript-foldable-traversable M Data.Traversable

A Traversable with an additional index.
A TraversableWithIndex instance must be compatible with its Traversable instance

traverse f = traverseWithIndex (const f)

with its FoldableWithIndex instance

foldMapWithIndex f = unwrap <<< traverseWithIndex (\i -> Const <<< f i)

and with its FunctorWithIndex instance

mapWithIndex f = unwrap <<< traverseWithIndex (\i -> Identity <<< f i)

A default implementation is provided by traverseWithIndexDefault.

P purescript-foldable-traversable M Data.TraversableWithIndex
P purescript-transformers M Control.Monad.Identity.Trans
P purescript-free M Data.Coyoneda
P purescript-array-views M Data.ArrayView.Internal
P purescript-identy M Identy.ObjectMap
P purescript-sql-squared M SqlSquared.Signature
P purescript-sequences M Data.FingerTree
P purescript-remotedata M Network.RemoteData