import { Either } from 'effect'
// Type signature: Either.Either<"left", "right">
const eitherWithReturn = Either.gen(function* (_) {
if (0 > 1) {
yield* _(Either.left('left' as const))
}
return 'right' as const
})
// Type signature: Either.Either<"left", "right">
const eitherWithReturnYield = Either.gen(function* (_) {
if (0 > 1) {
yield* _(Either.left('left' as const))
}
return yield* _(Either.right('right' as const))
})
console.log(eitherWithReturn) // { _id: 'Either', _tag: 'Right', right: undefined }
console.log(eitherWithReturnYield) // { _id: 'Either', _tag: 'Right', right: 'right' }
import { Either } from 'effect'
// Type signature: Either.Either<"left", "right">
const eitherWithReturn = Either.gen(function* (_) {
if (0 > 1) {
yield* _(Either.left('left' as const))
}
return 'right' as const
})
// Type signature: Either.Either<"left", "right">
const eitherWithReturnYield = Either.gen(function* (_) {
if (0 > 1) {
yield* _(Either.left('left' as const))
}
return yield* _(Either.right('right' as const))
})
console.log(eitherWithReturn) // { _id: 'Either', _tag: 'Right', right: undefined }
console.log(eitherWithReturnYield) // { _id: 'Either', _tag: 'Right', right: 'right' }