import type * as P from "@principia/prelude"; import * as HKT from "@principia/prelude/HKT"; import { Functor } from "./functor"; import { isLeft } from "./guards"; import type { Either, URI, V } from "./model"; /** * ```haskell * alt_ :: Alt f => (f a, (() -> f a)) -> f a * ``` * * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to types of kind `* -> *`. * * @category Alt * @since 1.0.0 */ export const alt_ = (fa: Either, that: () => Either): Either => isLeft(fa) ? that() : fa; /** * ```haskell * alt :: Alt f => (() -> f a) -> f a -> f a * ``` * * Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to types of kind `* -> *`. * * @category Alt * @since 1.0.0 */ export const alt = (that: () => Either) => (fa: Either): Either => alt_(fa, that); /** * @category Instances * @since 1.0.0 */ export const Alt: P.Alt<[URI], V> = HKT.instance({ ...Functor, alt_, alt });