on master help sign in
Comments in Prelude.Traversable
commit8885f72fe039a6898616d5cb123479f7954d4f90 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateFri 22 Jul 2016, 12:56 (10 years ago) parent0b9a9f8
1 file changed+8
libs/prelude/Prelude/Traversable.idr+8
libs/prelude/Prelude/Traversable.idr+8
@@ -9,20 +9,28 @@ import Prelude.Functor
99
1010%access public export
1111
12+||| Map each element of a structure to a computation, evaluate those
13+||| computations and discard the results.
1214traverse_ : (Foldable t, Applicative f) => (a -> f b) -> t a -> f ()
1315traverse_ f = foldr ((*>) . f) (pure ())
1416
17+||| Evaluate each computation in a structure and discard the results
1518sequence_ : (Foldable t, Applicative f) => t (f a) -> f ()
1619sequence_ = foldr (*>) (pure ())
1720
21+||| Like `traverse_` but with the arguments flipped
1822for_ : (Foldable t, Applicative f) => t a -> (a -> f b) -> f ()
1923for_ = flip traverse_
2024
2125interface (Functor t, Foldable t) => Traversable (t : Type -> Type) where
26+ ||| Map each element of a structure to a computation, evaluate those
27+ ||| computations and combine the results.
2228 traverse : Applicative f => (a -> f b) -> t a -> f (t b)
2329
30+||| Evaluate each computation in a structure and collect the results
2431sequence : (Traversable t, Applicative f) => t (f a) -> f (t a)
2532sequence = traverse id
2633
34+||| Like `traverse` but with the arguments flipped
2735for : (Traversable t, Applicative f) => t a -> (a -> f b) -> f (t b)
2836for = flip traverse