scala - Monad transformer for Disjunction and Future -
i have code returning future[string \/ response], monad instances both disjunction , future , function getresult: response => [string \/ result]. written several nested functions , want see following
for { response <- getresponse result <- getresult(response) } yield result // future[string \/ result] as can understand monad transformers using purpose , similar things if had option instead of \/. unfortunately couldn't found futuret nor disjunctiont (although xort exists cats).
so, possible write monad transformer above purpose? may exist or don't understand something.
you can use scalaz.eithert combine effects of \/ (disjunction) , monad, in case future.
def getresponse: future[string \/ response] = ??? def getresult(resp: reponse): future[string \/ result] = ??? (for { response <- eithert(getresponse) result <- eithert(getresult(response)) } yield result).run // future[string \/ result] or change return types of getresponse , getresult functions return eithert :
type r[a] = eithert[future, string, a] def getresponse: r[response] = ??? def getresult(resp: reponse): r[result] = ??? (for { response <- getresponse result <- getresult(response) } yield result).run // future[string \/ result]
Comments
Post a Comment