hey, great articles cycle. waiting for the next one!
after you got T.Task<Error | Resp> from TaskEither how would you take the value out?
with the use of one of the destructors like getOrElse or any better way?
I mean I want to get Error or Resp out of a Task<> as a value.
Task is just a promise, so you can just await it and use an if statement.
import*asTfrom'fp-ts/lib/Task'typeResp={code:number;description:string}declareconsttask:T.Task<Error|Resp>(async()=>{constresult=awaittask()if(resultinstanceofError){// Result is Error}else{// Result is Resp}})()
hey, great articles cycle. waiting for the next one!
after you got
T.Task<Error | Resp>
from TaskEither how would you take the value out?with the use of one of the destructors like getOrElse or any better way?
I mean I want to get Error or Resp out of a Task<> as a value.
Task is just a promise, so you can just
await
it and use an if statement.That section of the post didn't make of a lot of sense. I've rewritten it so the final type is
T.Task<Resp>
, since an error should never occur.I think adding
absurd, constVoid, unsafeCoerce
without explanation only made it harder to understand for beginners.