Tim Cowlishaw
unread,Feb 14, 2012, 6:19:01 PM2/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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