Module Data.Traversable

Functors representing data structures that can be traversed from left to right.

Imports

Table of Content

Definitions

class (Functor t, Foldable t) ⇒ Traversable t

Functors representing data structures that can be traversed from left to right.

Minimal complete definition: Traversable.traverse or Traversable.sequenceA.

The superclass instances should satisfy the following:

In the Functor instance, Functor.fmap should be equivalent to traversal with the identity applicative functor (fmapDefault).

In the Foldable instance, Foldable.foldMap should be equivalent to traversal with a constant applicative functor (foldMapDefault).

Note that the functions Traversable.mapM, Traversable.sequence, forM are just specialized versions of Traversable.traverse, Traversable.sequenceA and for, and wouldn't be required in Frege. They are included for Haskell compatibility only. In Haskell the specialized functions are needed as Haskell monads are no Applicatives.

Known Instances

Maybe, Identity.Identity, []

Member Functions

mapM ∷ (Traversable t, Monad m) ⇒ (a → m b) → t a → m (t b)

Map each element of a structure to a monadic action, evaluate these actions from left to right, and collect the results. This function exists for Haskell compatibility only.

sequence ∷ (Traversable t, Monad m) ⇒ t (m a) → m (t a)

Evaluate each monadic action in the structure from left to right, and collect the results. This function exists for Haskell compatibility only.

sequenceA ∷ (Traversable t, Applicative f) ⇒ t (f a) → f (t a)

Evaluate each action in the structure from left to right, and collect the results.

traverse ∷ (Traversable t, Applicative f) ⇒ (a → f b) → t a → f (t b)

Map each element of a structure to an action, evaluate these actions from left to right, and collect the results.

for ∷ (Traversable t, Applicative f) ⇒ t a → (a → f b) → f (t b)

for is Traversable.traverse with its arguments flipped.

forM ∷ (Traversable t, Monad m) ⇒ t a → (a → m b) → m (t b)

forM is Traversable.mapM with its arguments flipped.

This function exists for Haskell compatibility only.

data StateL s a

Constructors

StateL {run ∷ s → (s, a)}

Member Functions

runStateL 𝖇 𝖆 → 𝖇 → (𝖇, 𝖆)

access field run

mapAccumLTraversable t ⇒ (a → b → (a, c)) → a → t b → (a, t c)

The mapAccumL function behaves like a combination of Functor.fmap and Foldable.fold; it applies a function to each element of a structure, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new structure.

data StateR s a

Constructors

StateR {run ∷ s → (s, a)}

Member Functions

runStateR 𝖇 𝖆 → 𝖇 → (𝖇, 𝖆)

access field run

mapAccumRTraversable t ⇒ (a → b → (a, c)) → a → t b → (a, t c)

The mapAccumR function behaves like a combination of Functor.fmap and Foldable.foldr; it applies a function to each element of a structure, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new structure.

fmapDefaultTraversable t ⇒ (a → b) → t a → t b

This function may be used as a value for `fmap` in a `Functor` instance, provided that Traversable.traverse is defined. (Using fmapDefault with a Traversable instance defined only by Traversable.sequenceA will result in infinite recursion.)

foldMapDefault ∷ (Traversable t, Monoid m) ⇒ (a → m) → t a → m

This function may be used as a value for `Data.Foldable.foldMap` in a `Foldable` instance.

Instances

instance Applicative (StateL s)

Member Functions

*>StateL 𝖆 𝖇StateL 𝖆 𝖈StateL 𝖆 𝖈
infixl  4

inherited from Applicative.*>

<*StateL 𝖆 𝖇StateL 𝖆 𝖈StateL 𝖆 𝖇
infixl  4

inherited from Applicative.<*

<*>StateL 𝖆 (𝖇→𝖈)StateL 𝖆 𝖇StateL 𝖆 𝖈
infixl  4
pure ∷ 𝖇 → StateL 𝖆 𝖇
instance Applicative (StateR s)

Member Functions

*>StateR 𝖆 𝖇StateR 𝖆 𝖈StateR 𝖆 𝖈
infixl  4

inherited from Applicative.*>

<*StateR 𝖆 𝖇StateR 𝖆 𝖈StateR 𝖆 𝖇
infixl  4

inherited from Applicative.<*

<*>StateR 𝖆 (𝖇→𝖈)StateR 𝖆 𝖇StateR 𝖆 𝖈
infixl  4
pure ∷ 𝖇 → StateR 𝖆 𝖇
instance Functor (StateL s)

Member Functions

fmap ∷ (𝖇 → 𝖈) → StateL 𝖆 𝖇StateL 𝖆 𝖈
infixl  4
instance Functor (StateR s)

Member Functions

fmap ∷ (𝖇 → 𝖈) → StateR 𝖆 𝖇StateR 𝖆 𝖈
infixl  4
instance Traversable Identity

Member Functions

mapMMonad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Identity 𝖆 → 𝖈 (Identity 𝖇)

inherited from Traversable.mapM

sequenceMonad 𝖇 ⇒ Identity (𝖇 𝖆) → 𝖇 (Identity 𝖆)

inherited from Traversable.sequence

sequenceAApplicative 𝖇 ⇒ Identity (𝖇 𝖆) → 𝖇 (Identity 𝖆)

inherited from Traversable.sequenceA

traverseApplicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Identity 𝖆 → 𝖈 (Identity 𝖇)
instance Traversable Maybe

Member Functions

mapMMonad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Maybe 𝖆 → 𝖈 (Maybe 𝖇)

inherited from Traversable.mapM

sequenceMonad 𝖇 ⇒ Maybe (𝖇 𝖆) → 𝖇 (Maybe 𝖆)

inherited from Traversable.sequence

sequenceAApplicative 𝖇 ⇒ Maybe (𝖇 𝖆) → 𝖇 (Maybe 𝖆)

inherited from Traversable.sequenceA

traverseApplicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Maybe 𝖆 → 𝖈 (Maybe 𝖇)
instance Traversable []

Member Functions

mapMMonad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → [𝖆] → 𝖈 [𝖇]
sequenceMonad 𝖇 ⇒ [𝖇 𝖆] → 𝖇 [𝖆]

inherited from Traversable.sequence

sequenceAApplicative 𝖇 ⇒ [𝖇 𝖆] → 𝖇 [𝖆]

inherited from Traversable.sequenceA

traverseApplicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → [𝖆] → 𝖈 [𝖇]

Functions and Values by Type

𝖆 → Bool

StateL.has$run, StateR.has$run

(s → (s, a)) → StateL s a

StateL.StateL

(s → (s, a)) → StateR s a

StateR.StateR

StateL 𝖇 𝖆 → 𝖇 → (𝖇, 𝖆)

StateL.run

StateR 𝖇 𝖆 → 𝖇 → (𝖇, 𝖆)

StateR.run

𝖇 → StateL 𝖆 𝖇

Applicative_StateL.pure

𝖇 → StateR 𝖆 𝖇

Applicative_StateR.pure

Applicative 𝖇 ⇒ Identity (𝖇 𝖆) → 𝖇 (Identity 𝖆)

Traversable_Identity.sequenceA

Applicative 𝖇 ⇒ Maybe (𝖇 𝖆) → 𝖇 (Maybe 𝖆)

Traversable_Maybe.sequenceA

Applicative 𝖇 ⇒ [𝖇 𝖆] → 𝖇 [𝖆]

Traversable_[].sequenceA

Monad 𝖇 ⇒ Identity (𝖇 𝖆) → 𝖇 (Identity 𝖆)

Traversable_Identity.sequence

Monad 𝖇 ⇒ Maybe (𝖇 𝖆) → 𝖇 (Maybe 𝖆)

Traversable_Maybe.sequence

Monad 𝖇 ⇒ [𝖇 𝖆] → 𝖇 [𝖆]

Traversable_[].sequence

(𝖇 → 𝖈) → StateL 𝖆 𝖇 → StateL 𝖆 𝖈

Functor_StateL.fmap

(𝖇 → 𝖈) → StateR 𝖆 𝖇 → StateR 𝖆 𝖈

Functor_StateR.fmap

StateL 𝖆 (𝖇→𝖈) → StateL 𝖆 𝖇 → StateL 𝖆 𝖈

Applicative_StateL.<*>

StateL 𝖆 𝖇 → StateL 𝖆 𝖈 → StateL 𝖆 𝖇

Applicative_StateL.<*

StateL 𝖆 𝖇 → StateL 𝖆 𝖈 → StateL 𝖆 𝖈

Applicative_StateL.*>

StateR 𝖆 (𝖇→𝖈) → StateR 𝖆 𝖇 → StateR 𝖆 𝖈

Applicative_StateR.<*>

StateR 𝖆 𝖇 → StateR 𝖆 𝖈 → StateR 𝖆 𝖇

Applicative_StateR.<*

StateR 𝖆 𝖇 → StateR 𝖆 𝖈 → StateR 𝖆 𝖈

Applicative_StateR.*>

Traversable t ⇒ (a → b) → t a → t b

fmapDefault

(Traversable t, Monoid m) ⇒ (a → m) → t a → m

foldMapDefault

(Traversable t, Applicative f) ⇒ t (f a) → f (t a)

Traversable.sequenceA

(Traversable t, Monad m) ⇒ t (m a) → m (t a)

Traversable.sequence

Applicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Identity 𝖆 → 𝖈 (Identity 𝖇)

Traversable_Identity.traverse

Applicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Maybe 𝖆 → 𝖈 (Maybe 𝖇)

Traversable_Maybe.traverse

Applicative 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → [𝖆] → 𝖈 [𝖇]

Traversable_[].traverse

Monad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Identity 𝖆 → 𝖈 (Identity 𝖇)

Traversable_Identity.mapM

Monad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → Maybe 𝖆 → 𝖈 (Maybe 𝖇)

Traversable_Maybe.mapM

Monad 𝖈 ⇒ (𝖆 → 𝖈 𝖇) → [𝖆] → 𝖈 [𝖇]

Traversable_[].mapM

StateL 𝖆 𝖇 → (-> 𝖆 (𝖆, 𝖇)→𝖉→(𝖉, 𝖈)) → StateL 𝖉 𝖈

StateL.chg$run

StateL 𝖆 𝖇 → (𝖉→(𝖉, 𝖈)) → StateL 𝖉 𝖈

StateL.upd$run

StateR 𝖆 𝖇 → (-> 𝖆 (𝖆, 𝖇)→𝖉→(𝖉, 𝖈)) → StateR 𝖉 𝖈

StateR.chg$run

StateR 𝖆 𝖇 → (𝖉→(𝖉, 𝖈)) → StateR 𝖉 𝖈

StateR.upd$run

Traversable t ⇒ (a → b → (a, c)) → a → t b → (a, t c)

mapAccumL, mapAccumR

(Traversable t, Applicative f) ⇒ (a → f b) → t a → f (t b)

Traversable.traverse

(Traversable t, Applicative f) ⇒ t a → (a → f b) → f (t b)

for

(Traversable t, Monad m) ⇒ (a → m b) → t a → m (t b)

Traversable.mapM

(Traversable t, Monad m) ⇒ t a → (a → m b) → m (t b)

forM

Valid HTML 4.01 Strict