Scalaz equivalent of Haskell's 'sequence' combinator?

25 views
Skip to first unread message

Tim Cowlishaw

unread,
Feb 14, 2012, 6:19:01 PM2/14/12
to scalaz
Hi all,

I've written an iteratee instance that outputs the values yielded to
it to a file, stopping after a given number of lines. By sequencing
multiple instances of this iteratee together using their monad
instance, I hope to be able to output the yielded values of an
enumerator of arbitrary length to a sequence of files:

def fileWriteWithLimit(fileName : String, limit : Integer) :
IterV[String, ()]

def writeMultipleFiles(fileName : String) : IterV[String, ()] = {
val someArbitraryLimit = 200
Stream.from(0).map { fileWriteWithLimit(_fileName + "-" + _,
someArbitraryLimit).reduce((a,b) => a >>= {_ => b})
}

However, the final part of this (the 'reduce' over the list of
iteratees) looks rather unwieldy. In Haskell, I'd use the 'sequence'
or 'sequence_' combinator (of types Monad m => [m a] -> m [a] and
Monad m => [m a] -> m () respectively) to achieve this - does scalaz
offer an equivalent function to sequence a list of monadic actions?

Thanks,

Tim

Tim Cowlishaw

unread,
Feb 15, 2012, 4:01:39 AM2/15/12
to scalaz
Heh, sorry all, disregard that - I found it in the obvious place. It
was late in my timezone when I posted the question!

Thanks

Tim

Reply all
Reply to author
Forward
0 new messages