UNPKG

@typed/fp

Version:

Data Structures and Resources for fp-ts

192 lines 3.27 kB
import * as E from 'fp-ts/Either'; import { flow, pipe } from 'fp-ts/function'; import * as O from 'fp-ts/Option'; import * as OT from 'fp-ts/OptionT'; import * as D from './Data'; /** * @since 0.9.2 * @category Combinator */ export const alt = OT.alt(D.Monad); /** * @since 0.9.2 * @category Combinator */ export const ap = OT.ap(D.Apply); /** * @since 0.9.2 * @category Combinator */ export const chain = OT.chain(D.Monad); /** * @since 0.9.2 * @category Combinator */ export const chainNullableK = OT.chainNullableK(D.Monad); /** * @since 0.9.2 * @category Combinator */ /** * @since 0.9.2 * @category Combinator */ export const chainOptionK = OT.chainOptionK(D.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromEither = OT.fromEither(D.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromData = OT.fromF(D.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromNullable = OT.fromNullable(D.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromNullableK = OT.fromNullableK(D.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromOptionK = OT.fromOptionK(D.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromPredicate = OT.fromPredicate(D.Pointed); /** * @since 0.9.2 * @category Combinator */ export const getOrElse = OT.getOrElse(D.Functor); /** * @since 0.9.2 * @category Combinator */ export const getOrElseE = OT.getOrElseE(D.Monad); /** * @since 0.9.2 * @category Combinator */ export const map = OT.map(D.Functor); /** * @since 0.9.2 * @category Deconstructor */ export const match = OT.match(D.Functor); /** * @since 0.9.2 * @category Deconstructor */ export const matchE = OT.matchE(D.Chain); /** * @since 0.9.2 * @category Constructor */ export const some = OT.some(D.Pointed); /** * @since 0.9.2 * @category Constructor */ export const zero = OT.zero(D.Pointed); /** * @since 0.9.2 * @category URI */ export const URI = '@typed/fp/DataOption'; /** * @since 0.9.2 * @category Instance */ export const Pointed = { of: flow(O.some, D.of), }; /** * @since 0.9.2 * @category Instance */ export const Functor = { map, }; /** * @since 0.9.2 * @category Instance */ export const Apply = { ...Functor, ap, }; /** * @since 0.9.2 * @category Instance */ export const Applicative = { ...Apply, ...Pointed, }; /** * @since 0.9.2 * @category Instance */ export const Chain = { ...Functor, chain, }; /** * @since 0.9.2 * @category Combinator */ export const chainRec = (f) => D.chainRec(flow(f, D.map((oe) => { if (O.isNone(oe)) { return E.right(oe); } return pipe(oe.value, E.map(O.some)); }))); /** * @since 0.9.2 * @category Instance */ export const ChainRec = { chainRec, }; /** * @since 0.9.2 * @category Instance */ export const Monad = { ...Chain, ...Pointed, }; /** * @since 0.9.2 * @category Instance */ export const MonadRec = { ...Monad, ...ChainRec, }; /** * @since 0.9.2 * @category Instance */ export const Alt = { ...Functor, alt, }; /** * @since 0.9.2 * @category Instance */ export const Alternative = { ...Alt, zero, }; //# sourceMappingURL=DataOption.js.map