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}})()
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.
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, unsafeCoercewithout explanation only made it harder to understand for beginners.Task is just a promise, so you can just
awaitit and use an if statement.