/** * FromStream is a Typeclass which represents the Natural Transformation from a Stream into another * effect. * * @since 0.9.2 */ import { Chain, Chain1, Chain2, Chain3, Chain4, chainFirst } from 'fp-ts/Chain' import { flow } from 'fp-ts/function' import { HKT, URIS, URIS2, URIS3, URIS4 } from 'fp-ts/HKT' import { NaturalTransformation11, NaturalTransformation12, NaturalTransformation12C, NaturalTransformation13, NaturalTransformation13C, NaturalTransformation14, NaturalTransformation14C, } from 'fp-ts/NaturalTransformation' import { Hkt } from './HKT' import * as S from './Stream' /** * @since 0.9.2 * @category Typeclass */ export type FromStream = { readonly URI?: F readonly fromStream: (Stream: S.Stream) => HKT } /** * @since 0.9.2 * @category Typeclass */ export type FromStream1 = { readonly URI?: F readonly fromStream: NaturalTransformation11 } /** * @since 0.9.2 * @category Typeclass */ export type FromStream2 = { readonly URI?: F readonly fromStream: NaturalTransformation12 } /** * @since 0.9.2 * @category Typeclass */ export type FromStream2C = { readonly URI?: F readonly fromStream: NaturalTransformation12C } /** * @since 0.9.2 * @category Typeclass */ export type FromStream3 = { readonly URI?: F readonly fromStream: NaturalTransformation13 } /** * @since 0.9.2 * @category Typeclass */ export type FromStream3C = { readonly URI?: F readonly fromStream: NaturalTransformation13C } /** * @since 0.9.2 * @category Typeclass */ export type FromStream4 = { readonly URI?: F readonly fromStream: NaturalTransformation14 } /** * @since 0.9.2 * @category Typeclass */ export type FromStream4C = { readonly URI?: F readonly fromStream: NaturalTransformation14C } /** * @since 0.9.2 * @category Constructor */ export function fromStreamK( F: FromStream1, ): (f: (...args: A) => S.Stream) => (...args: A) => Hkt export function fromStreamK( F: FromStream2, ): ( f: (...args: A) => S.Stream, ) => (...args: A) => Hkt export function fromStreamK( F: FromStream3, ): ( f: (...args: A) => S.Stream, ) => (...args: A) => Hkt export function fromStreamK( F: FromStream4, ): ( f: (...args: A) => S.Stream, ) => (...args: A) => Hkt export function fromStreamK( F: FromStream, ): (f: (...args: A) => S.Stream) => (...args: A) => Hkt export function fromStreamK(F: FromStream) { return (f: (...args: A) => S.Stream) => (...args: A): HKT => F.fromStream(f(...args)) } /** * @since 0.9.2 * @category Combinator */ export function chainStreamK( F: FromStream1, C: Chain1, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainStreamK( F: FromStream2, C: Chain2, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainStreamK( F: FromStream3, C: Chain3, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainStreamK( F: FromStream4, C: Chain4, ): ( f: (value: A) => S.Stream, ) => (hkt: Hkt) => Hkt export function chainStreamK( F: FromStream, C: Chain, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainStreamK( F: FromStream, C: Chain, ): (f: (value: A) => S.Stream) => (hkt: HKT) => HKT { return (f) => C.chain(flow(f, F.fromStream)) } /** * @since 0.9.2 * @category Combinator */ export function chainFirstStreamK( F: FromStream1, C: Chain1, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainFirstStreamK( F: FromStream2, C: Chain2, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainFirstStreamK( F: FromStream3, C: Chain3, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainFirstStreamK( F: FromStream4, C: Chain4, ): ( f: (value: A) => S.Stream, ) => (hkt: Hkt) => Hkt export function chainFirstStreamK( F: FromStream, C: Chain, ): (f: (value: A) => S.Stream) => (hkt: Hkt) => Hkt export function chainFirstStreamK( F: FromStream, C: Chain, ): (f: (value: A) => S.Stream) => (hkt: HKT) => HKT { const chainF = chainFirst(C) return (f) => chainF(flow(f, F.fromStream)) }