import { curry } from '@typed/lambda'
import { chain } from './chain'
import { Either } from './Either'
import { map } from './map'
/**
* Applies the function contains in an `Either` to the value contained in a
* second `Either`.
* @name ap(fn: Either C>, value: Either): Either
*/
export const ap = curry(__ap) as {
(fn: Either C>, value: Either): Either
(fn: Either C>): (value: Either) => Either
}
function __ap(fn: Either C>, value: Either): Either {
return chain((f) => map(f, value), fn)
}