/** * FromKV is a Typeclass which represents the Natural Transformation from an KV into another * effect. * * @since 0.11.0 */ import { Chain, Chain2, Chain3, Chain4, chainFirst } from 'fp-ts/Chain' import { flow } from 'fp-ts/function' import { HKT, HKT2, Kind2, Kind3, Kind4, URIS2, URIS3, URIS4 } from 'fp-ts/HKT' import { ApplyVariance, Hkt, Initial } from './HKT' import * as KV from './KV' import * as Provide from './Provide' /** * @since 0.11.0 * @category Typeclass */ export type FromKV = { readonly URI?: F readonly fromKV: (KV: KV.KV) => HKT2 } /** * @since 0.11.0 * @category Combinator */ export type FromKV2 = { readonly URI?: F readonly fromKV: (KV: KV.KV) => Kind2 } /** * @since 0.11.0 * @category Typeclass */ export type FromKV3 = { readonly URI?: F readonly fromKV: >(KV: KV.KV) => Kind3 } /** * @since 0.11.0 * @category Typeclass */ export type FromKV3C = { readonly URI?: F readonly fromKV: (KV: KV.KV) => Kind3 } /** * @since 0.11.0 * @category Typeclass */ export type FromKV4 = { readonly URI?: F readonly fromKV: , E = Initial>( KV: KV.KV, ) => Kind4 } /** * @since 0.11.0 * @category Constructor */ export function fromKVK( F: FromKV2, ): ( f: (...args: A) => KV.KV, ) => (...args: A) => Hkt export function fromKVK( F: FromKV3, ): ( f: (...args: A) => KV.KV, ) => (...args: A) => Hkt export function fromKVK( F: FromKV4, ): ( f: (...args: A) => KV.KV, ) => (...args: A) => Hkt export function fromKVK( F: FromKV, ): ( f: (...args: A) => KV.KV, ) => (...args: A) => Hkt export function fromKVK(F: FromKV) { return (f: (...args: A) => KV.KV) => (...args: A) => F.fromKV(f(...args)) } /** * @since 0.11.0 * @category Combinator */ export function chainKVK( F: FromKV2, C: Chain2, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, B]> export function chainKVK( F: FromKV3, C: Chain3, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, E, B]> export function chainKVK( F: FromKV4, C: Chain4, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, E, B]> export function chainKVK( F: FromKV, C: Chain, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, B]> export function chainKVK( F: FromKV, C: Chain, ): (f: (value: A) => KV.KV) => (hkt: HKT) => HKT { return (f) => C.chain(flow(f, F.fromKV) as any) } /** * @since 0.11.0 * @category Combinator */ export function chainFirstKVK( F: FromKV2, C: Chain2, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, A]> export function chainFirstKVK( F: FromKV3, C: Chain3, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, E, A]> export function chainFirstKVK( F: FromKV4, C: Chain4, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, E, A]> export function chainFirstKVK( F: FromKV, C: Chain, ): ( f: (value: A) => KV.KV, ) => (hkt: Hkt) => Hkt, A]> export function chainFirstKVK( F: FromKV, C: Chain, ): (f: (value: A) => KV.KV) => (hkt: HKT) => HKT { const chainF = chainFirst(C) return (f) => chainF(flow(f, F.fromKV) as any) } /** * @since 0.11.0 * @category Combinator */ export function provideSomeWithKV( F: FromKV4 & Provide.ProvideSome4 & Chain4, ): (resume: KV.KV) => Provide.Provider4, Initial> export function provideSomeWithKV( F: FromKV3 & Provide.ProvideSome3 & Chain3, ): (resume: KV.KV) => Provide.Provider3> export function provideSomeWithKV( F: FromKV2 & Provide.ProvideSome2 & Chain2, ): (resume: KV.KV) => Provide.Provider2 export function provideSomeWithKV( F: FromKV & Provide.ProvideSome & Chain, ): (resume: KV.KV) => Provide.Provider export function provideSomeWithKV(F: FromKV & Provide.ProvideSome & Chain) { return flow(F.fromKV, Provide.provideSomeWith(F)) } /** * @since 0.11.0 * @category Combinator */ export function provideAllWithKV( F: FromKV4 & Provide.ProvideAll4 & Chain4, ): (resume: KV.KV) => (hkt: Kind4) => Kind4 export function provideAllWithKV( F: FromKV3 & Provide.ProvideAll3 & Chain3, ): (resume: KV.KV) => (hkt: Kind3) => Kind3 export function provideAllWithKV( F: FromKV2 & Provide.ProvideAll2 & Chain2, ): (resume: KV.KV) => (hkt: Kind2) => Kind2 export function provideAllWithKV( F: FromKV & Provide.ProvideAll & Chain, ): (resume: KV.KV) => (hkt: HKT2) => HKT2 export function provideAllWithKV(F: FromKV & Provide.ProvideAll & Chain) { return flow(F.fromKV, Provide.provideAllWith(F)) } /** * @since 0.11.0 * @category Combinator */ export function useSomeWithKV( F: FromKV4 & Provide.UseSome4 & Chain4, ): (resume: KV.KV) => Provide.Provider4, Initial> export function useSomeWithKV( F: FromKV3 & Provide.UseSome3 & Chain3, ): (resume: KV.KV) => Provide.Provider3> export function useSomeWithKV( F: FromKV2 & Provide.UseSome2 & Chain2, ): (resume: KV.KV) => Provide.Provider2 export function useSomeWithKV( F: FromKV & Provide.UseSome & Chain, ): (resume: KV.KV) => Provide.Provider export function useSomeWithKV(F: FromKV & Provide.UseSome & Chain) { return flow(F.fromKV, Provide.useSomeWith(F)) } /** * @since 0.11.0 * @category Combinator */ export function useAllWithKV( F: FromKV4 & Provide.UseAll4 & Chain4, ): (resume: KV.KV) => (hkt: Kind4) => Kind4 export function useAllWithKV( F: FromKV3 & Provide.UseAll3 & Chain3, ): (resume: KV.KV) => (hkt: Kind3) => Kind3 export function useAllWithKV( F: FromKV2 & Provide.UseAll2 & Chain2, ): (resume: KV.KV) => (hkt: Kind2) => Kind2 export function useAllWithKV( F: FromKV & Provide.UseAll & Chain, ): (resume: KV.KV) => (hkt: HKT2) => HKT2 export function useAllWithKV(F: FromKV & Provide.UseAll & Chain) { return flow(F.fromKV, Provide.useAllWith(F)) }