I'm not sure I understand exactly what you're looking for, but it sounds like you want something more like traverse
here (where traverse
is a more general version of Haskell's mapM
):
import scalaz._, Scalaz._
def adder(i: Int) = State[String, Int](str => (str + i.toString + " ", i))
List(1, 2, 3).traverseS(adder)("start: ")._1
This will print the following, as expected:
res0: String = "start: 1 2 3 "
Note that I'm using traverseS
(where the S
stands for State
) to avoid having to write out the rather messy type parameter, but traverse
is more generally useful anytime you want to map a monadic function over something traversable.
I'm happy to give a StateT
example if this isn't what you wanted, but that's going to end up with you having something of type List[(String, Int)]
.