monadsidrisidris2# What is the equivalent of mapM and mapM_ in idris2?

I know there is the `mapM`

function that applies a monadic action to a list and returns one monadic value containing a list. (See e.g.
What is the difference between mapM_ and mapM in Haskell?)

But I couldn't find any `mapM`

(or `mapM_`

or the underlying `sequence`

) function in idris2 (as of 0.6.0). The only thing I could find is a foldM.

*Am I expected to roll out my own version of mapM based on foldM, or is it provided elsewhere in Idris2?*

Solution

I think you want

```
traverse : Traversable t => Applicative f => (a -> f b) -> t a -> f (t b)
```

```
traverse_ : Applicative f => Foldable t => (a -> f b) -> t a -> f ()
```

Note `sequence = traverse id`

.

- Haskell fails to infer the return type of a monad after using the sequence operator
- Is this property of a functor stronger than a monad?
- What's the difference between C++23's optional::transform and optional::and_then?
- Codensity and ContT
- Monads in JavaScript
- Is there a non-identity monad morphism M ~> M that is monadically natural in M?
- Understanding bind function in Haskell
- Haskell [parse error, possibly incorrect indentation or mismatched brackets) parser
- Read instance for Associative Computations Tree
- Defining new keywords in F#'s computation expression
- Name and existence of functor or monad to chain and terminate sequence of operations
- How to write generic Monad law tests?
- Monad instance for Associative Computations Tree
- Is Future in Scala a monad?
- How to define custom operator in computational expression
- How can I use `liftIO` with State to print values inside that Monad?
- Migrating to Dart null safety: best practice for migrating ternary operator null checks? Is a monadic approach too unconventional?
- Haskells bind operator and the >> operator and their relation
- OCaml Addable Numbers
- What does <* in Haskell readP do?
- Haskell map on Right value of Either
- How to draw randomly-placed rectangles in Haskell's SDL2 bindings?
- Understanding the RWST in Haskell
- Parallel Haskell. Rate-Limiting the Producer
- Reader Monad in Haskell. Where is the reader passed as argument?
- Haskell interpreter, dont know how to run and test it
- What is the equivalent of mapM and mapM_ in idris2?
- Why can't a monad be decomposed?
- Haskell: inline auxiliary function into do block
- Defining a monad in Haskell