UNPKG

@typed/fp

Version:

Data Structures and Resources for fp-ts

363 lines 6.36 kB
/** * ReaderOption is an OptionT of fp-ts/Reader * @since 0.9.2 */ import * as Alt_ from 'fp-ts/Alt'; import * as Ap from 'fp-ts/Apply'; import * as CH from 'fp-ts/Chain'; import * as Ei from 'fp-ts/Either'; import * as FR from 'fp-ts/FromReader'; import { flow, pipe } from 'fp-ts/function'; import * as O from 'fp-ts/Option'; import * as OT from 'fp-ts/OptionT'; import * as R from './Reader'; /** * @since 0.9.2 * @category Combinator */ export const alt = OT.alt(R.Monad); /** * @since 0.9.2 * @category Combinator */ export const altW = OT.alt(R.Monad); /** * @since 0.9.2 * @category Combinator */ export const ap = OT.ap(R.Apply); /** * @since 0.9.2 * @category Combinator */ export const chain = OT.chain(R.Monad); /** * @since 0.9.2 * @category Combinator */ export const chainNullableK = OT.chainNullableK(R.Monad); /** * @since 0.9.2 * @category Combinator */ export const chainOptionK = OT.chainOptionK(R.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromEither = OT.fromEither(R.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromReader = OT.fromF(R.Monad); /** * @since 0.9.2 * @category Constructor */ export const fromNullable = OT.fromNullable(R.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromNullableK = OT.fromNullableK(R.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromOptionK = OT.fromOptionK(R.Pointed); /** * @since 0.9.2 * @category Constructor */ export const fromPredicate = OT.fromPredicate(R.Pointed); /** * @since 0.9.2 * @category Deconstructor */ export const getOrElse = OT.getOrElse(R.Functor); /** * @since 0.13.0 * @category Deconstructor */ export const getOrElseW = getOrElse; /** * @since 0.9.2 * @category Deconsructor */ export const getOrElseE = OT.getOrElseE(R.Monad); /** * @since 0.9.2 * @category Deconstructor */ export const getOrElseEW = OT.getOrElseE(R.Monad); /** * @since 0.9.2 * @category Combinator */ export const map = OT.map(R.Functor); /** * @since 0.9.2 * @category Deconstructor */ export const match = OT.match(R.Functor); /** * @since 0.9.2 * @category Deconstructor */ export const matchE = OT.matchE(R.Chain); /** * @since 0.13.0 * @category Deconstructor */ export const matchEW = matchE; /** * @since 0.9.2 * @category Constructor */ export const some = OT.some(R.Pointed); /** * @since 0.9.2 * @category Constructor */ export const zero = OT.zero(R.Pointed); /** * @since 0.9.2 * @category URI */ export const URI = '@typed/fp/ReaderOption'; /** * @since 0.9.2 * @category Instance */ export const Pointed = { of: flow(O.some, R.of), }; /** * @since 0.9.2 * @category Instance */ export const Functor = { map, }; /** * @since 0.9.2 * @category Instance */ export const Apply = { ...Functor, ap, }; /** * @since 0.12.2 * @category Constructor */ export const apFirst = Ap.apFirst(Apply); /** * @since 0.12.2 * @category Constructor */ export const apFirstW = apFirst; /** * @since 0.12.2 * @category Constructor */ export const apS = Ap.apS(Apply); /** * @since 0.12.2 * @category Constructor */ export const apSW = apS; /** * @since 0.12.2 * @category Constructor */ export const apSecond = Ap.apSecond(Apply); /** * @since 0.12.2 * @category Constructor */ export const apSecondW = apSecond; /** * @since 0.12.2 * @category Constructor */ export const apT = Ap.apT(Apply); /** * @since 0.12.2 * @category Constructor */ export const apTW = apT; /** * @since 0.12.2 * @category Typeclass Instance */ export const getApplySemigroup = Ap.getApplySemigroup(Apply); /** * @since 0.9.2 * @category Instance */ export const Applicative = { ...Apply, ...Pointed, }; /** * @since 0.9.2 * @category Instance */ export const Chain = { ...Functor, chain, }; /** * @since 0.12.2 * @category Constructor */ export const bind = CH.bind(Chain); /** * @since 0.12.2 * @category Constructor */ export const chainFirst = CH.chainFirst(Chain); /** * @since 0.9.2 * @category Combinator */ export const chainRec = (f) => (value) => pipe(value, R.chainRec((a) => pipe(a, f, R.map((oe) => { if (O.isNone(oe)) { return Ei.right(oe); } return pipe(oe.value, Ei.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.12.2 * @category Constructor */ export const altAll = Alt_.altAll(Alt); /** * @since 0.9.2 * @category Instance */ export const Alternative = { ...Alt, zero, }; /** * @since 0.9.2 * @category Instance */ export const FromIO = { fromIO: fromReader, }; /** * @since 0.9.2 * @category Constructor */ export const fromIO = FromIO.fromIO; /** * @since 0.9.2 * @category Instance */ export const FromReader = { fromReader, }; /** * @since 0.9.2 * @category Instance */ export const UseSome = { useSome: R.useSome, }; /** * @since 0.9.2 * @category Instance */ export const UseAll = { useAll: R.useAll, }; /** * @since 0.9.2 * @category Instance */ export const ProvideSome = { provideSome: R.provideSome, }; /** * @since 0.9.2 * @category Instance */ export const ProvideAll = { provideAll: R.provideAll, }; /** * @since 0.9.2 * @category Instance */ export const Provide = { ...UseAll, ...UseSome, ...ProvideSome, ...ProvideAll, }; /** * @since 0.9.2 * @category Constructor */ export const ask = FR.ask(FromReader); /** * @since 0.9.2 * @category Constructor */ export const asks = FR.asks(FromReader); /** * @since 0.9.2 * @category Combinator */ export const chainReaderK = FR.chainReaderK(FromReader, Chain); /** * @since 0.9.2 * @category Combinator */ export const chainFirstReaderK = FR.chainFirstReaderK(FromReader, Chain); /** * @since 0.9.2 * @category Constructor */ export const fromReaderK = FR.fromReaderK(FromReader); /** * @since 0.9.2 * @category Combinator */ export const local = (f) => (ro) => (a) => ro(f(a)); //# sourceMappingURL=ReaderOption.js.map