@matechs/effect
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -56,3 +56,3 @@ "use strict"; | ||
var completed = T.effectMonad.chain(T.effectMonad.result(source), complete); | ||
return T.effectMonad.onInterrupted(T.provide(r)(completed), interrupt); | ||
return T.effectMonad.onInterrupted(function (_) { return completed(r); }, interrupt); | ||
}; | ||
@@ -59,0 +59,0 @@ return { |
@@ -33,2 +33,3 @@ import * as Ei from "fp-ts/lib/Either"; | ||
tryPromise<E, A>(ioPromise: IO<Promise<A>>, onLeft: (e: any) => E): Kind3<T, NoEnv, E, A>; | ||
tryAsync<E, A>(op: FunctionN<[FunctionN<[Ei.Either<E, A>], void>], Lazy<void>>): Kind3<T, NoEnv, E, A>; | ||
provide<R, R2, E, A>(ma: Kind3<T, R2 & R, E, A>, r: R): Kind3<T, R2, E, A>; | ||
@@ -65,3 +66,3 @@ accessM<R, R2, E, A>(f: (r: R) => Kind3<T, R2, E, A>): Kind3<T, R & R2, E, A>; | ||
export declare function getCauseValidationM<E>(S: Semigroup<Cause<E>>): Monad3EC<URI, E> & MonadThrow3EC<URI, E> & Alt3EC<URI, E>; | ||
export declare const ap: <R, E, A, R2, E2>(fa: Effect<R, E, A>) => <B>(fab: Effect<R2, E2, (a: A) => B>) => Effect<R & R2, E | E2, B>, apFirst: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, apSecond: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chain: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chainFirst: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, flatten: <R, E, R2, E2, A>(mma: Effect<R, E, Effect<R2, E2, A>>) => Effect<R & R2, E | E2, A>, map: <A, B>(f: (a: A) => B) => <R, E>(fa: Effect<R, E, A>) => Effect<R, E, B>, bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => <R>(fa: Effect<R, E, A>) => Effect<R, G, B>, filterOrElse: { | ||
export declare const ap: <R, E, A, E2>(fa: Effect<R, E, A>) => <R2, B>(fab: Effect<R2, E2, (a: A) => B>) => Effect<R & R2, E | E2, B>, apFirst: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, apSecond: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chain: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>, chainFirst: <R, E, A, B>(f: (a: A) => Effect<R, E, B>) => <R2, E2>(ma: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, flatten: <R, E, R2, E2, A>(mma: Effect<R, E, Effect<R2, E2, A>>) => Effect<R & R2, E | E2, A>, map: <A, B>(f: (a: A) => B) => <R, E>(fa: Effect<R, E, A>) => Effect<R, E, B>, bimap: <E, G, A, B>(f: (e: E) => G, g: (a: A) => B) => <R>(fa: Effect<R, E, A>) => Effect<R, G, B>, filterOrElse: { | ||
<E, A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>, onFalse: (a: A) => E): <R>(ma: Effect<R, E, A>) => Effect<R, E, B>; | ||
@@ -73,3 +74,3 @@ <E_1, A_1>(predicate: import("fp-ts/lib/function").Predicate<A_1>, onFalse: (a: A_1) => E_1): <R_1>(ma: Effect<R_1, E_1, A_1>) => Effect<R_1, E_1, A_1>; | ||
}, mapLeft: <E, G>(f: (e: E) => G) => <R, A>(fa: Effect<R, E, A>) => Effect<R, G, A>; | ||
export declare const parAp: <R, E, A, R2, E2>(fa: Effect<R, E, A>) => <B>(fab: Effect<R2, E2, (a: A) => B>) => Effect<R & R2, E | E2, B>, parApFirst: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, parApSecond: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>; | ||
export declare const parAp: <R, E, A, E2>(fa: Effect<R, E, A>) => <R2, B>(fab: Effect<R2, E2, (a: A) => B>) => Effect<R & R2, E | E2, B>, parApFirst: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, A>, parApSecond: <R, E, B>(fb: Effect<R, E, B>) => <A, R2, E2>(fa: Effect<R2, E2, A>) => Effect<R & R2, E | E2, B>; | ||
export declare function error(message: string): Error; | ||
@@ -92,3 +93,3 @@ export declare const unit: Effect<NoEnv, NoErr, void>; | ||
export declare function left<E, A = never>(e: E): Effect<NoEnv, E, A>; | ||
export declare function fromIO<A>(io: IO<A>): Effect<NoEnv, never, A>; | ||
export declare function fromIO<E = never, A = unknown>(io: IO<A>): Effect<NoEnv, E, A>; | ||
export declare function uninterruptible<R, E, A>(io: Effect<R, E, A>): Effect<R, E, A>; | ||
@@ -98,2 +99,3 @@ export declare function interruptible<R, E, A>(io: Effect<R, E, A>): Effect<R, E, A>; | ||
export declare function tryPromise<E, A>(onLeft: (e: any) => E): (ioPromise: IO<Promise<A>>) => Effect<NoEnv, E, A>; | ||
export declare function tryAsync<E, A>(op: FunctionN<[FunctionN<[Ei.Either<E, A>], void>], Lazy<void>>): Effect<NoEnv, E, A>; | ||
export declare function chainLeft<E, E2, A, R2>(onLeft: (e: E) => Effect<R2, E2, A>): <R>(ma: Effect<R, E, A>) => Effect<R & R2, E2, A>; | ||
@@ -108,3 +110,3 @@ export declare function delay<R, E, A>(inner: Effect<R, E, A>, ms: number): Effect<R, E, A>; | ||
export declare function alt<R, E, A>(ma: Effect<R, E, A>): (mb: Effect<R, E, A>) => (predicate: boolean) => Effect<R, E, A>; | ||
export declare function mergeEnv<A, B>(a: A): (b: B) => A & B; | ||
export declare function mergeEnv<A>(a: A): <B>(b: B) => A & B; | ||
export declare const noEnv: {}; | ||
@@ -111,0 +113,0 @@ export declare const provide: <R>(r: R) => <R2, E, A>(ma: Effect<R2 & R, E, A>) => Effect<R2, E, A>; |
@@ -13,2 +13,5 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -23,5 +26,5 @@ if (mod && mod.__esModule) return mod; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var deepmerge_1 = __importDefault(require("deepmerge")); | ||
var Ei = __importStar(require("fp-ts/lib/Either")); | ||
var Op = __importStar(require("fp-ts/lib/Option")); | ||
var M = __importStar(require("deepmerge")); | ||
var W = __importStar(require("waveguide/lib/wave")); | ||
@@ -88,4 +91,7 @@ var Ar = __importStar(require("fp-ts/lib/Array")); | ||
}, | ||
tryAsync: function (op) { | ||
return function (_) { return W.async(op); }; | ||
}, | ||
provide: function (ma, r) { | ||
return function (r2) { return ma(M.all([r, r2], { clone: false })); }; | ||
return function (r2) { return ma(deepmerge_1.default.all([r, r2], { clone: false })); }; | ||
}, | ||
@@ -200,2 +206,4 @@ accessM: function (f) { | ||
URI: exports.URI, | ||
// @ts-ignore | ||
_E: undefined, | ||
of: exports.effectMonad.of, | ||
@@ -299,2 +307,6 @@ map: exports.effectMonad.map, | ||
exports.tryPromise = tryPromise; | ||
function tryAsync(op) { | ||
return exports.effectMonad.tryAsync(op); | ||
} | ||
exports.tryAsync = tryAsync; | ||
function chainLeft(onLeft) { | ||
@@ -345,3 +357,3 @@ return function (ma) { return exports.effectMonad.chainLeft(ma, onLeft); }; | ||
function mergeEnv(a) { | ||
return function (b) { return M.all([a, b], { clone: false }); }; | ||
return function (b) { return deepmerge_1.default.all([a, b], { clone: false }); }; | ||
} | ||
@@ -348,0 +360,0 @@ exports.mergeEnv = mergeEnv; |
@@ -20,2 +20,5 @@ import "fp-ts-contrib/lib/Do"; | ||
import { NoEnv, NoErr } from "./index"; | ||
import { Either } from "fp-ts/lib/Either"; | ||
import { Option } from "fp-ts/lib/Option"; | ||
import { Refinement, Predicate } from "fp-ts/lib/function"; | ||
export interface Chain3E<F extends URIS3> extends Apply3<F> { | ||
@@ -32,3 +35,3 @@ readonly chain: <R, E, A, R2, E2, B>(fa: Kind3<F, R, E, A>, f: (a: A) => Kind3<F, R2, E2, B>) => Kind3<F, R & R2, E | E2, B>; | ||
export interface Apply3EC<F extends URIS3, E> extends Functor3EC<F, E> { | ||
readonly ap: <R, A, B>(fab: Kind3<F, R, E, (a: A) => B>, fa: Kind3<F, R, E, A>) => Kind3<F, R, E, B>; | ||
readonly ap: <R, R2, A, B>(fab: Kind3<F, R, E, (a: A) => B>, fa: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, B>; | ||
} | ||
@@ -40,5 +43,12 @@ export interface Chain3EC<F extends URIS3, E> extends Apply3EC<F, E> { | ||
readonly URI: F; | ||
readonly _E: E; | ||
readonly map: <R, A, B>(fa: Kind3<F, R, E, A>, f: (a: A) => B) => Kind3<F, R, E, B>; | ||
} | ||
declare type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R; | ||
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; | ||
export declare type ATypeOf<X> = X extends Kind3<infer M, infer R, infer E, infer A> ? A : never; | ||
export declare type RTypeOf<X> = X extends Kind3<infer M, infer R, infer E, infer A> ? R : never; | ||
export declare type EnvOf<R extends Record<string, Kind3<any, any, any, any>>> = UnionToIntersection<{ | ||
[K in keyof R]: unknown extends RTypeOf<R[K]> ? never : RTypeOf<R[K]>; | ||
}[keyof R]>; | ||
export interface Do3CE<M extends URIS3, S extends object, U, L> { | ||
@@ -53,17 +63,40 @@ do: <E, R>(ma: Kind3<M, R, E, unknown>) => Do3CE<M, S, U & R, L | E>; | ||
}, U & R, L | E>; | ||
sequenceS: <R extends Record<string, Kind3<M, U, L, any>>>(r: EnforceNonEmptyRecord<R> & { | ||
sequenceS: <R extends Record<string, Kind3<M, never, L, any>>>(r: EnforceNonEmptyRecord<R> & { | ||
[K in keyof S]?: never; | ||
}) => Do3CE<M, S & { | ||
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never; | ||
}, U, L>; | ||
sequenceSL: <R extends Record<string, Kind3<M, U, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & { | ||
[K in keyof R]: ATypeOf<R[K]>; | ||
}, U & EnvOf<R>, L>; | ||
sequenceSL: <R extends Record<string, Kind3<M, never, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & { | ||
[K in keyof S]?: never; | ||
}) => Do3CE<M, S & { | ||
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never; | ||
}, U, L>; | ||
[K in keyof R]: ATypeOf<R[K]>; | ||
}, U & EnvOf<R>, L>; | ||
return: <A>(f: (s: S) => A) => Kind3<M, U, L, A>; | ||
done: () => Kind3<M, U, L, S>; | ||
} | ||
export interface Do3CE_<M extends URIS3, S extends object, U, L> { | ||
do: <R>(ma: Kind3<M, R, L, unknown>) => Do3CE_<M, S, U & R, L>; | ||
doL: <R>(f: (s: S) => Kind3<M, R, L, unknown>) => Do3CE_<M, S, U & R, L>; | ||
bind: <N extends string, R, A>(name: Exclude<N, keyof S>, ma: Kind3<M, R, L, A>) => Do3CE_<M, S & { | ||
[K in N]: A; | ||
}, U & R, L>; | ||
bindL: <N extends string, R, A>(name: Exclude<N, keyof S>, f: (s: S) => Kind3<M, R, L, A>) => Do3CE_<M, S & { | ||
[K in N]: A; | ||
}, U & R, L>; | ||
sequenceS: <R extends Record<string, Kind3<M, never, L, any>>>(r: EnforceNonEmptyRecord<R> & { | ||
[K in keyof S]?: never; | ||
}) => Do3CE_<M, S & { | ||
[K in keyof R]: ATypeOf<R[K]>; | ||
}, U & EnvOf<R>, L>; | ||
sequenceSL: <R extends Record<string, Kind3<M, never, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & { | ||
[K in keyof S]?: never; | ||
}) => Do3CE_<M, S & { | ||
[K in keyof R]: ATypeOf<R[K]>; | ||
}, U & EnvOf<R>, L>; | ||
return: <A>(f: (s: S) => A) => Kind3<M, U, L, A>; | ||
done: () => Kind3<M, U, L, S>; | ||
} | ||
declare module "fp-ts-contrib/lib/Do" { | ||
function Do<M extends URIS3>(M: Monad3E<M>): Do3CE<M, {}, NoEnv, NoErr>; | ||
function Do<M extends URIS3, E>(M: Monad3EC<M, E>): Do3CE_<M, {}, NoEnv, E>; | ||
} | ||
@@ -75,7 +108,20 @@ export interface PipeableChain3E<F extends URIS3> extends PipeableApply3E<F> { | ||
} | ||
export interface PipeableChain3EC<F extends URIS3, E> extends PipeableApply3EC<F, E> { | ||
readonly chain: <R, A, B>(f: (a: A) => Kind3<F, R, E, B>) => <R2>(ma: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, B>; | ||
readonly chainFirst: <R, A, B>(f: (a: A) => Kind3<F, R, E, B>) => <R2>(ma: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, A>; | ||
readonly flatten: <R, R2, A>(mma: Kind3<F, R, E, Kind3<F, R2, E, A>>) => Kind3<F, R & R2, E, A>; | ||
} | ||
export interface PipeableApply3E<F extends URIS3> extends PipeableFunctor3<F> { | ||
readonly ap: <R, E, A, R2, E2>(fa: Kind3<F, R, E, A>) => <B>(fab: Kind3<F, R2, E2, (a: A) => B>) => Kind3<F, R & R2, E | E2, B>; | ||
readonly ap: <R, E, A, E2>(fa: Kind3<F, R, E, A>) => <R2, B>(fab: Kind3<F, R2, E2, (a: A) => B>) => Kind3<F, R & R2, E | E2, B>; | ||
readonly apFirst: <R, E, B>(fb: Kind3<F, R, E, B>) => <A, R2, E2>(fa: Kind3<F, R2, E2, A>) => Kind3<F, R & R2, E | E2, A>; | ||
readonly apSecond: <R, E, B>(fb: Kind3<F, R, E, B>) => <A, R2, E2>(fa: Kind3<F, R2, E2, A>) => Kind3<F, R & R2, E | E2, B>; | ||
} | ||
export interface PipeableApply3EC<F extends URIS3, E> extends PipeableFunctor3EC<F, E> { | ||
readonly ap: <R, A>(fa: Kind3<F, R, E, A>) => <B, R2>(fab: Kind3<F, R2, E, (a: A) => B>) => Kind3<F, R & R2, E, B>; | ||
readonly apFirst: <R, B>(fb: Kind3<F, R, E, B>) => <A, R2>(fa: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, A>; | ||
readonly apSecond: <R, B>(fb: Kind3<F, R, E, B>) => <A, R2>(fa: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, B>; | ||
} | ||
export interface PipeableFunctor3EC<F extends URIS3, E> { | ||
readonly map: <A, B>(f: (a: A) => B) => <R>(fa: Kind3<F, R, E, A>) => Kind3<F, R, E, B>; | ||
} | ||
export interface Apply3E<F extends URIS3> extends Functor3<F> { | ||
@@ -88,12 +134,30 @@ readonly ap: <R, E, A, B, R2, E2>(fab: Kind3<F, R, E, (a: A) => B>, fa: Kind3<F, R2, E2, A>) => Kind3<F, R & R2, E | E2, B>; | ||
} & I): (I extends Chain3E<F> ? PipeableChain3E<F> : I extends Apply3E<F> ? PipeableApply3E<F> : I extends Functor3<F> ? PipeableFunctor3<F> : {}) & (I extends Contravariant3<F> ? PipeableContravariant3<F> : {}) & (I extends FunctorWithIndex3<F, infer Ix> ? PipeableFunctorWithIndex3<F, Ix> : {}) & (I extends Bifunctor3<F> ? PipeableBifunctor3<F> : {}) & (I extends Extend3<F> ? PipeableExtend3<F> : {}) & (I extends FoldableWithIndex3<F, infer Ix> ? PipeableFoldableWithIndex3<F, Ix> : I extends Foldable3<F> ? PipeableFoldable3<F> : {}) & (I extends Alt3<F> ? PipeableAlt3<F> : {}) & (I extends FilterableWithIndex3<F, infer Ix> ? PipeableFilterableWithIndex3<F, Ix> : I extends Filterable3<F> ? PipeableFilterable3<F> : I extends Compactable3<F> ? PipeableCompactable3<F> : {}) & (I extends Profunctor3<F> ? PipeableProfunctor3<F> : {}) & (I extends Semigroupoid3<F> ? PipeableSemigroupoid3<F> : {}) & (I extends MonadThrow3E<F> ? PipeableMonadThrow3<F> : {}); | ||
function pipeable<F extends URIS3, I, E>(I: { | ||
URI: F; | ||
} & I): (I extends Chain3EC<F, E> ? PipeableChain3EC<F, E> : I extends Apply3EC<F, E> ? PipeableApply3EC<F, E> : I extends Functor3EC<F, E> ? PipeableFunctor3EC<F, E> : {}) & (I extends Alt3EC<F, E> ? PipeableAlt3EC<F, E> : {}) & (I extends MonadThrow3EC<F, E> ? PipeableMonadThrow3<F> : {}); | ||
} | ||
export interface MonadThrow3E<M extends URIS3> extends Monad3E<M> { | ||
readonly throwError: <R, E, A>(e: E) => Kind3<M, R, E, A>; | ||
readonly throwError: <E>(e: E) => Kind3<M, unknown, E, never>; | ||
} | ||
export interface MonadThrow3EC<M extends URIS3, E> extends Monad3EC<M, E> { | ||
readonly throwError: <R, A>(e: E) => Kind3<M, R, E, A>; | ||
readonly throwError: (e: E) => Kind3<M, unknown, E, never>; | ||
} | ||
export interface Alt3EC<F extends URIS3, E> extends Functor3EC<F, E> { | ||
readonly alt: <R, A>(fx: Kind3<F, R, E, A>, fy: () => Kind3<F, R, E, A>) => Kind3<F, R, E, A>; | ||
readonly alt: <R, R2, A>(fx: Kind3<F, R, E, A>, fy: () => Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, A>; | ||
} | ||
export interface PipeableAlt3EC<F extends URIS3, E> { | ||
readonly alt: <R, A>(that: () => Kind3<F, R, E, A>) => <R2>(fa: Kind3<F, R2, E, A>) => Kind3<F, R & R2, E, A>; | ||
} | ||
export interface PipeableMonadThrow3EC<F extends URIS3, E> { | ||
readonly fromOption: (onNone: () => E) => <R, A>(ma: Option<A>) => Kind3<F, R, E, A>; | ||
readonly fromEither: <R, A>(ma: Either<E, A>) => Kind3<F, R, E, A>; | ||
readonly fromPredicate: { | ||
<A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): <U>(a: A) => Kind3<F, U, E, B>; | ||
<A>(predicate: Predicate<A>, onFalse: (a: A) => E): <R>(a: A) => Kind3<F, R, E, A>; | ||
}; | ||
readonly filterOrElse: { | ||
<A, B extends A>(refinement: Refinement<A, B>, onFalse: (a: A) => E): <R>(ma: Kind3<F, R, E, A>) => Kind3<F, R, E, B>; | ||
<A>(predicate: Predicate<A>, onFalse: (a: A) => E): <R>(ma: Kind3<F, R, E, A>) => Kind3<F, R, E, A>; | ||
}; | ||
} | ||
export {}; |
@@ -0,4 +1,6 @@ | ||
/// <reference types="node" /> | ||
import { Option } from "fp-ts/lib/Option"; | ||
import { FunctionN, Lazy, Predicate } from "fp-ts/lib/function"; | ||
import { Eq } from "fp-ts/lib/Eq"; | ||
import * as managed from "../managed"; | ||
import { Managed } from "../managed"; | ||
@@ -8,2 +10,3 @@ import { Sink } from "./sink"; | ||
import { Monad3E } from "../overload"; | ||
import { ReadStream } from "fs"; | ||
export declare type Source<R, E, A> = T.Effect<R, E, Option<A>>; | ||
@@ -163,3 +166,3 @@ export declare type Fold<R, E, A> = <S>(initial: S, cont: Predicate<S>, step: FunctionN<[S, A], T.Effect<R, E, S>>) => T.Effect<R, E, S>; | ||
*/ | ||
export declare function scanM<R, E, A, B>(stream: Stream<R, E, A>, f: FunctionN<[B, A], T.Effect<R, E, B>>, seed: B): Stream<R, E, B>; | ||
export declare function scanM<R, E, A, B, R2, E2>(stream: Stream<R, E, A>, f: FunctionN<[B, A], T.Effect<R2, E2, B>>, seed: B): Stream<R & R2, E | E2, B>; | ||
/** | ||
@@ -189,2 +192,3 @@ * Purely scan a stream | ||
export declare function mapM<R, E, A, R2, E2, B>(stream: Stream<R, E, A>, f: FunctionN<[A], T.Effect<R2, E2, B>>): Stream<R & R2, E | E2, B>; | ||
export declare function mapMWith<A, R2, E2, B>(f: FunctionN<[A], T.Effect<R2, E2, B>>): <R, E>(stream: Stream<R, E, A>) => Stream<R & R2, E | E2, B>; | ||
/** | ||
@@ -316,1 +320,2 @@ * A stream that emits no elements but never terminates. | ||
export declare const instances: Monad3E<URI>; | ||
export declare function fromObjectReadStream<A>(stream: ReadStream): managed.Managed<unknown, Error, Fold<unknown, Error, A>>; |
@@ -63,2 +63,5 @@ "use strict"; | ||
var T = __importStar(require("../")); | ||
var Ei = __importStar(require("fp-ts/lib/Either")); | ||
var O = __importStar(require("fp-ts/lib/Option")); | ||
var stream_1 = require("stream"); | ||
// The contract of a Stream's fold is that state is preserved within the lifecycle of the managed | ||
@@ -280,18 +283,4 @@ // Therefore, we must track the offset in the array via a ref | ||
exports.zipWithIndex = zipWithIndex; | ||
function widenFold() { | ||
return function (f) { return f; }; | ||
} | ||
function widen() { | ||
return function (stream) { | ||
function fold(initial, cont, step) { | ||
return function (r2) { | ||
return pipeable_1.pipe(r2, managed.use(stream, function (f) { | ||
return widenFold()(f)(initial, cont, function (s, a) { return function (r) { | ||
return pipeable_1.pipe(step(s, a)(pipeable_1.pipe(r, T.mergeEnv(r2)))); | ||
}; }); | ||
})); | ||
}; | ||
} | ||
return managed.pure(fold); | ||
}; | ||
return function (stream) { return stream; }; | ||
} | ||
@@ -457,3 +446,3 @@ /** | ||
function scanM(stream, f, seed) { | ||
return concat(once(seed), pipeable_1.pipe(managed.zip(stream, managed.encaseEffect(ref.makeRef(seed))), managed.mapWith(function (_a) { | ||
return concat(once(seed), pipeable_1.pipe(managed.zip(widen()(stream), managed.encaseEffect(ref.makeRef(seed))), managed.mapWith(function (_a) { | ||
var base = _a[0], accum = _a[1]; | ||
@@ -534,2 +523,6 @@ function fold(initial, cont, step) { | ||
exports.mapM = mapM; | ||
function mapMWith(f) { | ||
return function (stream) { return chain(stream, function (a) { return encaseEffect(f(a)); }); }; | ||
} | ||
exports.mapMWith = mapMWith; | ||
/** | ||
@@ -999,2 +992,64 @@ * A stream that emits no elements but never terminates. | ||
}; | ||
/* extensions */ | ||
/* istanbul ignore next */ | ||
function getSourceFromObjectReadStream(stream) { | ||
return managed.encaseEffect(T.fromIO(function () { | ||
var open = true; | ||
var f; | ||
var leftover = []; | ||
var errors = []; | ||
stream.on("end", function () { | ||
if (f) { | ||
f(Ei.right(O.none)); | ||
} | ||
else { | ||
open = false; | ||
} | ||
}); | ||
stream.on("error", function (e) { | ||
if (f) { | ||
f(Ei.left(Ei.toError(e))); | ||
} | ||
else { | ||
errors.push(e); | ||
} | ||
}); | ||
stream.pipe(new stream_1.Writable({ | ||
objectMode: true, | ||
write: function (chunk, _, callback) { | ||
if (f) { | ||
f(Ei.right(O.some(chunk))); | ||
} | ||
else { | ||
leftover.push(chunk); | ||
} | ||
callback(); | ||
} | ||
})); | ||
return T.tryAsync(function (res) { | ||
if (leftover.length > 0) { | ||
res(Ei.right(leftover.splice(0, 1)[0])); | ||
} | ||
else { | ||
if (errors.length > 0) { | ||
res(Ei.left(errors[0])); | ||
} | ||
else { | ||
if (open) { | ||
f = res; | ||
} | ||
else { | ||
res(Ei.right(O.none)); | ||
} | ||
} | ||
} | ||
return function () { }; | ||
}); | ||
})); | ||
} | ||
/* istanbul ignore next */ | ||
function fromObjectReadStream(stream) { | ||
return fromSource(getSourceFromObjectReadStream(stream)); | ||
} | ||
exports.fromObjectReadStream = fromObjectReadStream; | ||
//# sourceMappingURL=stream.js.map |
{ | ||
"name": "@matechs/effect", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"license": "MIT", | ||
@@ -40,3 +40,3 @@ "private": false, | ||
}, | ||
"gitHead": "3ff547ce45a0fb1e20d3a8fe43e5cb42b1743fea" | ||
"gitHead": "e62abf750484c571e48848716e4b29361cc31d1d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
207245
3114