Converting a Task[Throwable \/ T] into a Task[T]

62 views
Skip to first unread message

Edmondo Porcu

unread,
Jun 13, 2015, 6:38:20 AM6/13/15
to sca...@googlegroups.com
Hello,

is there an idiomatic approach to create a task from a function with signature Throwable \/ T ?

I am using scalaz.streams and I found myself having a Process[Task, Throwable \/ T ] which is very inconvenient

Thank you

Edmondo

09goral

unread,
Jun 13, 2015, 7:06:11 AM6/13/15
to sca...@googlegroups.com
wouldn't you lose information?

Edmondo Porcu

unread,
Jun 13, 2015, 7:16:30 AM6/13/15
to sca...@googlegroups.com
A Task[T] is a scalaz.Future[Throwable \/ T], so I thought it would make sense not to duplicate the failure? 

Paul Chiusano

unread,
Jun 13, 2015, 6:10:15 PM6/13/15
to sca...@googlegroups.com
Use flatMap in conjunction with Task.fail

Paul :)
--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at http://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.

Bob Gleason

unread,
Jun 16, 2015, 3:35:24 PM6/16/15
to sca...@googlegroups.com
I'm not sure it's idiomatic, but new Task[T](Future(f)) always works for me:

import scalaz.\/
import scalaz.concurrent.{Future, Task}

def toTask[T](trier: => Throwable \/ T): Task[T] = new Task[T](Future(trier))

--Bob Gleason

Reply all
Reply to author
Forward
0 new messages