/** * @typed/fp/StateReaderTaskEither is an extension of fp-ts/StateReaderTaskEither with additional * type-class instances. * @since 0.9.2 */ import { ChainRec4 } from 'fp-ts/ChainRec' import * as E from 'fp-ts/Either' import { pipe } from 'fp-ts/function' import * as SRTE from 'fp-ts/StateReaderTaskEither' import { Arity1 } from './function' import { MonadRec4 } from './MonadRec' import { Provide4, ProvideAll4, ProvideSome4, UseAll4, UseSome4 } from './Provide' /** * @since 0.9.2 * @category Combinator */ export const chainRec = (f: Arity1>>) => (value: A): SRTE.StateReaderTaskEither => pipe(value, f, SRTE.chain(E.match(chainRec(f), SRTE.of))) /** * @since 0.9.2 * @category Instance */ export const ChainRec: ChainRec4 = { chainRec, } /** * @since 0.9.2 * @category Instance */ export const MonadRec: MonadRec4 = { ...SRTE.Monad, chainRec, } /** * @since 0.9.2 * @category Combinator */ export const useSome = (provided: R1) => ( srte: SRTE.StateReaderTaskEither, ): SRTE.StateReaderTaskEither => (s) => (r) => srte(s)({ ...r, ...provided }) /** * @since 0.9.2 * @category Combinator */ export const provideSome = (provided: R1) => ( srte: SRTE.StateReaderTaskEither, ): SRTE.StateReaderTaskEither => (s) => (r) => srte(s)({ ...provided, ...r }) /** * @since 0.9.2 * @category Combinator */ export const useAll = (provided: R) => ( srte: SRTE.StateReaderTaskEither, ): SRTE.StateReaderTaskEither => (s) => () => srte(s)(provided) /** * @since 0.9.2 * @category Combinator */ export const provideAll = (provided: R) => ( srte: SRTE.StateReaderTaskEither, ): SRTE.StateReaderTaskEither => (s) => (r) => srte(s)({ ...provided, ...(r as {}) }) /** * @since 0.9.2 * @category Instance */ export const UseSome: UseSome4 = { useSome, } /** * @since 0.9.2 * @category Instance */ export const UseAll: UseAll4 = { useAll, } /** * @since 0.9.2 * @category Instance */ export const ProvideSome: ProvideSome4 = { provideSome, } /** * @since 0.9.2 * @category Instance */ export const ProvideAll: ProvideAll4 = { provideAll, } /** * @since 0.9.2 * @category Instance */ export const Provide: Provide4 = { useSome, useAll, provideSome, provideAll, } export * from 'fp-ts/StateReaderTaskEither'