import { Either, isLeft } from './Either'
import { curry } from '@typed/lambda'
import { fromRight } from './Right'
/**
* Returns a `Either` that is the result of calling `f` with the resolved
* value of another `Either`.
* @name chain(f: (value: B) => Either, either: Either): Either
*/
export const chain = curry(__chain) as {
(f: (value: B) => Either, either: Either): Either
(f: (value: B) => Either): (either: Either) => Either
}
function __chain(f: (value: B) => Either, either: Either): Either {
return isLeft(either) ? either : f(fromRight(either))
}