UNPKG

@typed/fp

Version:

Data Structures and Resources for fp-ts

92 lines 1.93 kB
/** * RefAdapter is an abstraction over [Ref](./Ref.ts.md) and [Adapter](./Adapter.ts.md) * @since 0.11.0 */ import { identity } from 'fp-ts/function'; import { fst, snd } from 'fp-ts/Tuple2'; import * as A from './Adapter'; import * as E from './Env'; import { pipe } from './function'; import * as RS from './ReaderStream'; import * as Ref from './Ref'; /** * @since 0.12.0 * @category Combinator */ export function sendEvent(event) { return (ra) => pipe(ra.get, E.chainIOK(([send]) => () => send(event))); } /** * @since 0.11.0 * @category Combinator */ export function getSendEvent(ra) { return pipe(ra.get, E.map(fst)); } /** * @since 0.11.0 * @category Combinator */ export function getEvents(ra) { return pipe(ra.get, E.map(snd), RS.fromEnv, RS.chainStreamK(identity)); } /** * @since 0.12.0 * @category Combinator */ export function listenToEvents(f) { return (ra) => pipe(ra, getEvents, RS.chainEnvK(f)); } /** * @since 0.11.0 * @category Combinator */ export function map(f) { return (ra) => pipe(ra, Ref.map(A.map(f))); } /** * @since 0.11.0 * @category Combinator */ export function local(f) { return (ra) => pipe(ra, Ref.map(A.local(f))); } /** * @since 0.11.0 * @category Combinator */ export const promap = (f, g) => (adapter) => pipe(adapter, local(f), map(g)); /** * @since 0.11.0 * @category URI */ export const URI = '@typed/fp/RefAdapter'; /** * @since 0.11.0 * @category Instance */ export const Functor = { map, }; /** * @since 0.11.0 * @category Instance */ export const Profunctor = { map, promap, }; /** * @since 0.13.5 * @category Instance */ export function wrap(ra) { return { ...ra, sendEvent: (event) => pipe(ra, sendEvent(event)), getSendEvent: getSendEvent(ra), events: getEvents(ra), listenToEvents: (f) => pipe(ra, listenToEvents(f)), }; } //# sourceMappingURL=RefAdapter.js.map