Skip to content

Instantly share code, notes, and snippets.

@vieiralucas
Created April 7, 2019 23:12
Show Gist options
  • Select an option

  • Save vieiralucas/de8d21ac191a2210ffd82f1f23ae7f12 to your computer and use it in GitHub Desktop.

Select an option

Save vieiralucas/de8d21ac191a2210ffd82f1f23ae7f12 to your computer and use it in GitHub Desktop.
import { Option, none, some } from 'fp-ts/lib/Option'
import { TaskEither, fromLeft, taskEither } from 'fp-ts/lib/TaskEither'
const a = (): Option<number> => {
if (Math.random() > 0.5) {
return none
}
return some(1)
}
const b = (): Option<TaskEither<Error, number>> => {
return a().map(n => {
if (Math.random() > 0.5) {
return fromLeft(new Error('very unlucky'))
}
return taskEither.of(n)
})
}
const c = (): TaskEither<Error, Option<TaskEither<Error, number>>> => {
if (Math.random() > 0.5) {
return fromLeft(new Error('unlucky'))
}
return taskEither.of(b())
}
const x: TaskEither<Error, Option<TaskEither<Error, number>>> = c()
// how to get to this type from x?
const y: TaskEither<Error, Option<number>> = ???
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment