@typed/fp
Version:
Data Structures and Resources for fp-ts
56 lines • 1.36 kB
JavaScript
/**
* RefDataEither is a collection of helpers for working with Refs that manage DataEither.
* @since 0.12.1
*/
import { flow, pipe } from 'fp-ts/function';
import * as DE from './DataEither';
import * as E from './Env';
import * as Ref from './Ref';
/**
* @since 0.12.1
* @category Combinator
*/
export function toNoData(rd) {
return rd.update(() => E.of(DE.noData));
}
/**
* @since 0.12.1
* @category Combinator
*/
export function toLoading(rd) {
return rd.update(flow(DE.toLoading, E.of));
}
/**
* @since 0.12.1
* @category Combinator
*/
export function toRefresh(value, progress) {
return (rd) => rd.update(() => E.of(DE.refresh(value, progress)));
}
/**
* @since 0.12.1
* @category Combinator
*/
export function toReplete(value) {
return (rd) => rd.update(() => E.of(DE.replete(value)));
}
/**
* @since 0.12.1
* @category Combinator
*/
export function loadEnv(env) {
return (rd) => pipe(rd, toLoading, E.chainW(() => rd.update(() => pipe(env, E.map(DE.replete)))));
}
/**
* @since 0.12.1
* @category Combinator
*/
export function loadEnvEither(env) {
return (rd) => pipe(rd, toLoading, E.chainW(() => rd.update(() => pipe(env, E.map(DE.fromEither)))));
}
/**
* @since 0.12.1
* @category Combinator
*/
export const map = (f) => (ref) => pipe(ref, Ref.map(DE.map(f)));
//# sourceMappingURL=RefDataEither.js.map