Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fp-ts-contrib

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fp-ts-contrib - npm Package Compare versions

Comparing version 0.0.6 to 0.1.0

lib/batchTraverse.d.ts

9

CHANGELOG.md

@@ -16,2 +16,11 @@ # Changelog

# 0.1.0
- **Breaking Change**
- upgrade to `fp-ts@2.x` (@gcanti)
- rename `batchTraverseM` to `batchTraverse` (@gcanti)
- remove `batchSequenceM` (@gcanti)
- make `withTimeout` compatible with both `Task` and `TaskEither` (@gcanti)
- remove `TaskEither/withTimeout` (@gcanti)
# 0.0.6

@@ -18,0 +27,0 @@

13

lib/Align/Array.d.ts

@@ -17,6 +17,11 @@ import { URI } from 'fp-ts/lib/Array';

* @example
* import { Option } from 'fp-ts/lib/Option'
* import * as O from 'fp-ts/lib/Option'
* import { lpadZipWith } from 'fp-ts-contrib/lib/Align/Array'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* const f = (ma: Option<number>, b: string) => ma.fold('*', a => a.toString()) + b
* const f = (ma: O.Option<number>, b: string) =>
* pipe(
* ma,
* O.fold(() => '*', a => a.toString())
* ) + b
* assert.deepStrictEqual(lpadZipWith([1, 2, 3], ['a', 'b', 'c', 'd'], f), ['1a', '2b', '3c', '*d'])

@@ -51,6 +56,6 @@ * assert.deepStrictEqual(lpadZipWith([1, 2, 3, 4], ['a', 'b', 'c'], f), ['1a', '2b', '3c'])

* @example
* import { Option } from 'fp-ts/lib/Option'
* import { Option, getOrElse } from 'fp-ts/lib/Option'
* import { rpadZipWith } from 'fp-ts-contrib/lib/Align/Array'
*
* const f = (a: number, mb: Option<string>) => a.toString() + mb.getOrElse('*')
* const f = (a: number, mb: Option<string>) => a.toString() + getOrElse(() => '*')(mb)
* assert.deepStrictEqual(rpadZipWith([1, 2, 3, 4], ['a', 'b', 'c'], f), ['1a', '2b', '3c', '4*'])

@@ -57,0 +62,0 @@ * assert.deepStrictEqual(rpadZipWith([1, 2, 3], ['a', 'b', 'c', 'd'], f), ['1a', '2b', '3c'])

@@ -5,2 +5,3 @@ "use strict";

var Array_1 = require("fp-ts/lib/Array");
var Option_1 = require("fp-ts/lib/Option");
var function_1 = require("fp-ts/lib/function");

@@ -47,3 +48,3 @@ var _1 = require("./");

for (var i = bLen; i < aLen; i++) {
fc[i] = f(These_1.this_(fa[i]));
fc[i] = f(These_1.left(fa[i]));
}

@@ -53,3 +54,3 @@ }

for (var i = aLen; i < bLen; i++) {
fc[i] = f(These_1.that(fb[i]));
fc[i] = f(These_1.right(fb[i]));
}

@@ -68,4 +69,4 @@ }

* assert.deepStrictEqual(alignArray.align([1, 2], ['a', 'b']), [both(1, 'a'), both(2, 'b')])
* assert.deepStrictEqual(alignArray.align([1, 2], ['a']), [both(1, 'a'), this_(2)])
* assert.deepStrictEqual(alignArray.align([1], ['a' 'b']), [both(1, 'a'), that('b')])
* assert.deepStrictEqual(alignArray.align([1, 2], ['a']), [both(1, 'a'), left(2)])
* assert.deepStrictEqual(alignArray.align([1], ['a' 'b']), [both(1, 'a'), right('b')])
*

@@ -85,6 +86,11 @@ * @since 0.0.3

* @example
* import { Option } from 'fp-ts/lib/Option'
* import * as O from 'fp-ts/lib/Option'
* import { lpadZipWith } from 'fp-ts-contrib/lib/Align/Array'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* const f = (ma: Option<number>, b: string) => ma.fold('*', a => a.toString()) + b
* const f = (ma: O.Option<number>, b: string) =>
* pipe(
* ma,
* O.fold(() => '*', a => a.toString())
* ) + b
* assert.deepStrictEqual(lpadZipWith([1, 2, 3], ['a', 'b', 'c', 'd'], f), ['1a', '2b', '3c', '*d'])

@@ -96,3 +102,3 @@ * assert.deepStrictEqual(lpadZipWith([1, 2, 3, 4], ['a', 'b', 'c'], f), ['1a', '2b', '3c'])

function lpadZipWith(xs, ys, f) {
return Array_1.catOptions(_1.padZipWith(exports.alignArray)(xs, ys, function (ma, mb) { return mb.map(function (b) { return f(ma, b); }); }));
return Array_1.array.compact(_1.padZipWith(exports.alignArray)(xs, ys, function (ma, mb) { return Option_1.option.map(mb, function (b) { return f(ma, b); }); }));
}

@@ -126,6 +132,6 @@ exports.lpadZipWith = lpadZipWith;

* @example
* import { Option } from 'fp-ts/lib/Option'
* import { Option, getOrElse } from 'fp-ts/lib/Option'
* import { rpadZipWith } from 'fp-ts-contrib/lib/Align/Array'
*
* const f = (a: number, mb: Option<string>) => a.toString() + mb.getOrElse('*')
* const f = (a: number, mb: Option<string>) => a.toString() + getOrElse(() => '*')(mb)
* assert.deepStrictEqual(rpadZipWith([1, 2, 3, 4], ['a', 'b', 'c'], f), ['1a', '2b', '3c', '4*'])

@@ -132,0 +138,0 @@ * assert.deepStrictEqual(rpadZipWith([1, 2, 3], ['a', 'b', 'c', 'd'], f), ['1a', '2b', '3c'])

@@ -12,6 +12,6 @@ /**

*/
import { HKT, Type, Type2, Type3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { Semigroup } from 'fp-ts/lib/Semigroup';
import { Option } from 'fp-ts/lib/Option';
import { Semialign, Semialign1, Semialign2, Semialign2C, Semialign3, Semialign3C } from '../Semialign';
import { Semialign, Semialign1, Semialign2, Semialign2C, Semialign3 } from '../Semialign';
/**

@@ -23,16 +23,25 @@ * @since 0.0.3

}
/**
* @since 0.0.3
*/
export interface Align1<F extends URIS> extends Semialign1<F> {
readonly nil: <A>() => Type<F, A>;
readonly nil: <A>() => Kind<F, A>;
}
/**
* @since 0.0.3
*/
export interface Align2<F extends URIS2> extends Semialign2<F> {
readonly nil: <L, A>() => Type2<F, L, A>;
readonly nil: <L, A>() => Kind2<F, L, A>;
}
export interface Align3<F extends URIS3> extends Semialign3<F> {
readonly nil: <U, L, A>() => Type3<F, U, L, A>;
}
/**
* @since 0.0.3
*/
export interface Align2C<F extends URIS2, L> extends Semialign2C<F, L> {
readonly nil: <A>() => Type2<F, L, A>;
readonly nil: <A>() => Kind2<F, L, A>;
}
export interface Align3C<F extends URIS3, U, L> extends Semialign3C<F, U, L> {
readonly nil: <A>() => Type3<F, U, L, A>;
/**
* @since 0.0.3
*/
export interface Align3<F extends URIS3> extends Semialign3<F> {
readonly nil: <U, L, A>() => Kind3<F, U, L, A>;
}

@@ -51,7 +60,6 @@ /**

*/
export declare function salign<F extends URIS3, A, L>(F: Align3<F>, S: Semigroup<A>): <U, L>(fx: Type3<F, U, L, A>, fy: Type3<F, U, L, A>) => Type3<F, U, L, A>;
export declare function salign<F extends URIS3, A, U, L>(F: Align3C<F, U, L>, S: Semigroup<A>): (fx: Type3<F, U, L, A>, fy: Type3<F, U, L, A>) => Type3<F, U, L, A>;
export declare function salign<F extends URIS2, A>(F: Align2<F>, S: Semigroup<A>): <L>(fx: Type2<F, L, A>, fy: Type2<F, L, A>) => Type2<F, L, A>;
export declare function salign<F extends URIS2, A, L>(F: Align2C<F, L>, S: Semigroup<A>): (fx: Type2<F, L, A>, fy: Type2<F, L, A>) => Type2<F, L, A>;
export declare function salign<F extends URIS, A>(F: Align1<F>, S: Semigroup<A>): (fx: Type<F, A>, fy: Type<F, A>) => Type<F, A>;
export declare function salign<F extends URIS3, A, L>(F: Align3<F>, S: Semigroup<A>): <U, L>(fx: Kind3<F, U, L, A>, fy: Kind3<F, U, L, A>) => Kind3<F, U, L, A>;
export declare function salign<F extends URIS2, A>(F: Align2<F>, S: Semigroup<A>): <L>(fx: Kind2<F, L, A>, fy: Kind2<F, L, A>) => Kind2<F, L, A>;
export declare function salign<F extends URIS2, A, L>(F: Align2C<F, L>, S: Semigroup<A>): (fx: Kind2<F, L, A>, fy: Kind2<F, L, A>) => Kind2<F, L, A>;
export declare function salign<F extends URIS, A>(F: Align1<F>, S: Semigroup<A>): (fx: Kind<F, A>, fy: Kind<F, A>) => Kind<F, A>;
export declare function salign<F, A>(F: Align<F>, S: Semigroup<A>): (fx: HKT<F, A>, fy: HKT<F, A>) => HKT<F, A>;

@@ -72,7 +80,6 @@ /**

*/
export declare function padZip<F extends URIS3, L>(F: Align3<F>): <U, L, A, B>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>) => Type3<F, U, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS3, U, L>(F: Align3C<F, U, L>): <A, B>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>) => Type3<F, U, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS2>(F: Align2<F>): <L, A, B>(fa: Type2<F, L, A>, fb: Type2<F, L, B>) => Type2<F, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS2, L>(F: Align2C<F, L>): <A, B>(fa: Type2<F, L, A>, fb: Type2<F, L, B>) => Type2<F, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS>(F: Align1<F>): <A, B>(fa: Type<F, A>, fb: Type<F, B>) => Type<F, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS3, L>(F: Align3<F>): <U, L, A, B>(fa: Kind3<F, U, L, A>, fb: Kind3<F, U, L, B>) => Kind3<F, U, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS2>(F: Align2<F>): <L, A, B>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>) => Kind2<F, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS2, L>(F: Align2C<F, L>): <A, B>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>) => Kind2<F, L, [Option<A>, Option<B>]>;
export declare function padZip<F extends URIS>(F: Align1<F>): <A, B>(fa: Kind<F, A>, fb: Kind<F, B>) => Kind<F, [Option<A>, Option<B>]>;
export declare function padZip<F>(F: Align<F>): <A, B>(fa: HKT<F, A>, fb: HKT<F, B>) => HKT<F, [Option<A>, Option<B>]>;

@@ -85,7 +92,17 @@ /**

* @example
* import { Option } from 'fp-ts/lib/Option'
* import { Option, fold, getOrElse } from 'fp-ts/lib/Option'
* import { padZipWith } from 'fp-ts-contrib/lib/Align'
* import { alignArray } from 'fp-ts-contrib/lib/Align/Array'
* import { pipe } from 'fp-ts/lib/pipeable'
*
* const f = (ma: Option<number>, mb: Option<string>) => ma.fold('*', a => a.toString()) + mb.getOrElse('#')
* const f = (ma: Option<number>, mb: Option<string>) =>
* pipe(
* ma,
* fold(() => '*', a => a.toString())
* ) +
* pipe(
* mb,
* getOrElse(() => '#')
* )
*
* assert.deepStrictEqual(padZipWith(alignArray)([1, 2], ['a'], f), ['1a', '2#'])

@@ -96,7 +113,6 @@ * assert.deepStrictEqual(padZipWith(alignArray)([1], ['a', 'b'], f), ['1a', '*b'])

*/
export declare function padZipWith<F extends URIS3, L>(F: Align3<F>): <U, L, A, B, C>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Type3<F, U, L, C>;
export declare function padZipWith<F extends URIS3, U, L>(F: Align3C<F, U, L>): <A, B, C>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Type3<F, U, L, C>;
export declare function padZipWith<F extends URIS2>(F: Align2<F>): <L, A, B, C>(fa: Type2<F, L, A>, fb: Type2<F, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Type2<F, L, C>;
export declare function padZipWith<F extends URIS2, L>(F: Align2C<F, L>): <A, B, C>(fa: Type2<F, L, A>, fb: Type2<F, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Type2<F, L, C>;
export declare function padZipWith<F extends URIS>(F: Align1<F>): <A, B, C>(fa: Type<F, A>, fb: Type<F, B>, f: (a: Option<A>, b: Option<B>) => C) => Type<F, C>;
export declare function padZipWith<F extends URIS3, L>(F: Align3<F>): <U, L, A, B, C>(fa: Kind3<F, U, L, A>, fb: Kind3<F, U, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Kind3<F, U, L, C>;
export declare function padZipWith<F extends URIS2>(F: Align2<F>): <L, A, B, C>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Kind2<F, L, C>;
export declare function padZipWith<F extends URIS2, L>(F: Align2C<F, L>): <A, B, C>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>, f: (a: Option<A>, b: Option<B>) => C) => Kind2<F, L, C>;
export declare function padZipWith<F extends URIS>(F: Align1<F>): <A, B, C>(fa: Kind<F, A>, fb: Kind<F, B>, f: (a: Option<A>, b: Option<B>) => C) => Kind<F, C>;
export declare function padZipWith<F>(F: Align<F>): <A, B, C>(fa: HKT<F, A>, fb: HKT<F, B>, f: (a: Option<A>, b: Option<B>) => C) => HKT<F, C>;

@@ -5,4 +5,6 @@ "use strict";

var Option_1 = require("fp-ts/lib/Option");
var These_1 = require("fp-ts/lib/These");
var pipeable_1 = require("fp-ts/lib/pipeable");
function salign(F, S) {
return function (fx, fy) { return F.alignWith(fx, fy, function (xy) { return xy.fold(function_1.identity, function_1.identity, S.concat); }); };
return function (fx, fy) { return F.alignWith(fx, fy, These_1.fold(function_1.identity, function_1.identity, S.concat)); };
}

@@ -16,5 +18,7 @@ exports.salign = salign;

return function (fa, fb, f) {
return F.alignWith(fa, fb, function (ab) { return ab.bimap(Option_1.some, Option_1.some).fold(function (a) { return f(a, Option_1.none); }, function (b) { return f(Option_1.none, b); }, function (a, b) { return f(a, b); }); });
return F.alignWith(fa, fb, function (ab) {
return pipeable_1.pipe(ab, These_1.bimap(Option_1.some, Option_1.some), These_1.fold(function (a) { return f(a, Option_1.none); }, function (b) { return f(Option_1.none, b); }, function (a, b) { return f(a, b); }));
});
};
}
exports.padZipWith = padZipWith;

@@ -40,10 +40,10 @@ "use strict";

alignWith: function (fa, fb, f) {
if (fa.isSome() && fb.isSome()) {
if (Option_1.isSome(fa) && Option_1.isSome(fb)) {
return Option_1.some(f(These_1.both(fa.value, fb.value)));
}
else if (fa.isNone() && fb.isSome()) {
return Option_1.some(f(These_1.that(fb.value)));
else if (Option_1.isNone(fa) && Option_1.isSome(fb)) {
return Option_1.some(f(These_1.right(fb.value)));
}
else if (fa.isSome() && fb.isNone()) {
return Option_1.some(f(These_1.this_(fa.value)));
else if (Option_1.isSome(fa) && Option_1.isNone(fb)) {
return Option_1.some(f(These_1.left(fa.value)));
}

@@ -59,8 +59,8 @@ else {

* import { some, none } from 'fp-ts/lib/Option'
* import { both, this_, that } from 'fp-ts/lib/These'
* import { both, left, right } from 'fp-ts/lib/These'
* import { alignOption } from 'fp-ts-contrib/lib/Align/Option'
*
* assert.deepStrictEqual(alignOption.align(some(1), some('a')), some(both(1, 'a')))
* assert.deepStrictEqual(alignOption.align(some(1, none), some(this_(1)))
* assert.deepStrictEqual(alignOption.align(none, some('a')), some(that('a')))
* assert.deepStrictEqual(alignOption.align(some(1, none), some(left(1)))
* assert.deepStrictEqual(alignOption.align(none, some('a')), some(right('a')))
* assert.deepStrictEqual(alignOption.align(none, none), none)

@@ -67,0 +67,0 @@ *

@@ -14,3 +14,3 @@ "use strict";

else {
r[key] = f(These_1.this_(fa[key]));
r[key] = f(These_1.left(fa[key]));
}

@@ -21,3 +21,3 @@ }

if (!fa.hasOwnProperty(key)) {
r[key] = f(These_1.that(fb[key]));
r[key] = f(These_1.right(fb[key]));
}

@@ -24,0 +24,0 @@ }

@@ -0,26 +1,51 @@

import { Alt1 } from 'fp-ts/lib/Alt';
import { Monad1 } from 'fp-ts/lib/Monad';
import { Option } from 'fp-ts/lib/Option';
declare module 'fp-ts/lib/HKT' {
interface URI2HKT<A> {
interface URItoKind<A> {
ArrayOption: ArrayOption<A>;
}
}
/**
* @since 0.1.0
*/
export declare const URI = "ArrayOption";
/**
* @since 0.1.0
*/
export declare type URI = typeof URI;
export declare class ArrayOption<A> {
readonly value: Array<Option<A>>;
readonly _A: A;
readonly _URI: URI;
constructor(value: Array<Option<A>>);
map<B>(f: (a: A) => B): ArrayOption<B>;
ap<B>(fab: ArrayOption<(a: A) => B>): ArrayOption<B>;
ap_<B, C>(this: ArrayOption<(b: B) => C>, fb: ArrayOption<B>): ArrayOption<C>;
chain<B>(f: (a: A) => ArrayOption<B>): ArrayOption<B>;
fold<R>(onNone: R, onSome: (a: A) => R): Array<R>;
getOrElse(a: A): Array<A>;
/**
* @since 0.1.0
*/
export interface ArrayOption<A> extends Array<Option<A>> {
}
/**
* @since 0.1.0
*/
export declare const fromArray: <A>(as: Array<A>) => ArrayOption<A>;
/**
* @since 0.1.0
*/
export declare const fromOption: <A>(ma: Option<A>) => ArrayOption<A>;
/**
* @since 0.1.0
*/
export declare const none: ArrayOption<never>;
/**
* @since 0.1.0
*/
export declare const some: <A>(a: A) => ArrayOption<A>;
export declare const none: ArrayOption<never>;
export declare const fromOption: <A>(ma: Option<A>) => ArrayOption<A>;
export declare const fromArray: <A>(ma: A[]) => ArrayOption<A>;
export declare const arrayOption: Monad1<URI>;
/**
* @since 0.1.0
*/
export declare function fold<A, B>(onNone: () => Array<B>, onSome: (a: A) => Array<B>): (as: ArrayOption<A>) => Array<B>;
/**
* @since 0.1.0
*/
export declare function getOrElse<A>(onNone: () => Array<A>): (as: ArrayOption<A>) => Array<A>;
/**
* @since 0.1.0
*/
export declare const arrayOption: Monad1<URI> & Alt1<URI>;
declare const alt: <A>(that: () => ArrayOption<A>) => (fa: ArrayOption<A>) => ArrayOption<A>, ap: <A>(fa: ArrayOption<A>) => <B>(fab: ArrayOption<(a: A) => B>) => ArrayOption<B>, apFirst: <B>(fb: ArrayOption<B>) => <A>(fa: ArrayOption<A>) => ArrayOption<A>, apSecond: <B>(fb: ArrayOption<B>) => <A>(fa: ArrayOption<A>) => ArrayOption<B>, chain: <A, B>(f: (a: A) => ArrayOption<B>) => (ma: ArrayOption<A>) => ArrayOption<B>, chainFirst: <A, B>(f: (a: A) => ArrayOption<B>) => (ma: ArrayOption<A>) => ArrayOption<A>, flatten: <A>(mma: ArrayOption<ArrayOption<A>>) => ArrayOption<A>, map: <A, B>(f: (a: A) => B) => (fa: ArrayOption<A>) => ArrayOption<B>;
export { alt, ap, apFirst, apSecond, chain, chainFirst, flatten, map };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Array_1 = require("fp-ts/lib/Array");
var Option_1 = require("fp-ts/lib/Option");
var optionT = require("fp-ts/lib/OptionT");
var function_1 = require("fp-ts/lib/function");
var OptionT_1 = require("fp-ts/lib/OptionT");
var pipeable_1 = require("fp-ts/lib/pipeable");
var T = OptionT_1.getOptionM(Array_1.array);
/**
* @since 0.1.0
*/
exports.URI = 'ArrayOption';
var T = optionT.getOptionT2v(Array_1.array);
var foldT = optionT.fold(Array_1.array);
var ArrayOption = /** @class */ (function () {
function ArrayOption(value) {
this.value = value;
}
ArrayOption.prototype.map = function (f) {
return new ArrayOption(T.map(this.value, f));
};
ArrayOption.prototype.ap = function (fab) {
return new ArrayOption(T.ap(fab.value, this.value));
};
ArrayOption.prototype.ap_ = function (fb) {
return fb.ap(this);
};
ArrayOption.prototype.chain = function (f) {
return new ArrayOption(T.chain(this.value, function (a) { return f(a).value; }));
};
ArrayOption.prototype.fold = function (onNone, onSome) {
return foldT(onNone, onSome, this.value);
};
ArrayOption.prototype.getOrElse = function (a) {
return this.fold(a, function_1.identity);
};
return ArrayOption;
}());
exports.ArrayOption = ArrayOption;
var map = function (fa, f) { return fa.map(f); };
var of = function (a) { return new ArrayOption(T.of(a)); };
var ap = function (fab, fa) { return fa.ap(fab); };
var chain = function (fa, f) { return fa.chain(f); };
exports.some = of;
exports.none = new ArrayOption(Array_1.array.of(Option_1.none));
exports.fromOption = function (ma) { return new ArrayOption(Array_1.array.of(ma)); };
exports.fromArray = function (ma) { return new ArrayOption(ma.map(Option_1.some)); };
/**
* @since 0.1.0
*/
exports.fromArray = T.fromM;
/**
* @since 0.1.0
*/
exports.fromOption = Array_1.of;
/**
* @since 0.1.0
*/
exports.none = T.none();
/**
* @since 0.1.0
*/
exports.some = T.of;
/**
* @since 0.1.0
*/
function fold(onNone, onSome) {
return function (as) { return T.fold(as, onNone, onSome); };
}
exports.fold = fold;
/**
* @since 0.1.0
*/
function getOrElse(onNone) {
return function (as) { return T.getOrElse(as, onNone); };
}
exports.getOrElse = getOrElse;
/**
* @since 0.1.0
*/
exports.arrayOption = {
URI: exports.URI,
map: map,
of: of,
ap: ap,
chain: chain
map: T.map,
of: exports.some,
ap: T.ap,
chain: T.chain,
alt: T.alt
};
var _a = pipeable_1.pipeable(exports.arrayOption), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map;
exports.alt = alt;
exports.ap = ap;
exports.apFirst = apFirst;
exports.apSecond = apSecond;
exports.chain = chain;
exports.chainFirst = chainFirst;
exports.flatten = flatten;
exports.map = map;

@@ -1,116 +0,113 @@

/**
* @file This module provides a simuation of Haskell do notation.
*/
import { HKT, Type, Type2, URIS, URIS2, URIS3, Type3 } from 'fp-ts/lib/HKT';
import { Monad, Monad1, Monad2, Monad2C, Monad3, Monad3C } from 'fp-ts/lib/Monad';
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { Monad, Monad1, Monad2, Monad2C, Monad3 } from 'fp-ts/lib/Monad';
declare type EnforceNonEmptyRecord<R> = keyof R extends never ? never : R;
export interface Do3<M extends URIS3, S extends object> {
do: <U, L>(ma: Type3<M, U, L, unknown>) => Do3C<M, S, U, L>;
doL: <U, L>(f: (s: S) => Type3<M, U, L, unknown>) => Do3C<M, S, U, L>;
bind: <N extends string, A, U, L>(name: Exclude<N, keyof S>, ma: Type3<M, U, L, A>) => Do3C<M, S & {
do: <U, L>(ma: Kind3<M, U, L, unknown>) => Do3C<M, S, U, L>;
doL: <U, L>(f: (s: S) => Kind3<M, U, L, unknown>) => Do3C<M, S, U, L>;
bind: <N extends string, A, U, L>(name: Exclude<N, keyof S>, ma: Kind3<M, U, L, A>) => Do3C<M, S & {
[K in N]: A;
}, U, L>;
bindL: <N extends string, A, U, L>(name: Exclude<N, keyof S>, f: (s: S) => Type3<M, U, L, A>) => Do3C<M, S & {
bindL: <N extends string, A, U, L>(name: Exclude<N, keyof S>, f: (s: S) => Kind3<M, U, L, A>) => Do3C<M, S & {
[K in N]: A;
}, U, L>;
sequenceS: <U, L, R extends Record<string, Type3<M, U, L, any>>>(r: EnforceNonEmptyRecord<R> & Record<string, Type3<M, U, L, any>> & {
sequenceS: <U, L, R extends Record<string, Kind3<M, U, L, any>>>(r: EnforceNonEmptyRecord<R> & Record<string, Kind3<M, U, L, any>> & {
[K in keyof S]?: never;
}) => Do3C<M, S & {
[K in keyof R]: [R[K]] extends [Type3<M, any, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never;
}, U, L>;
sequenceSL: <U, L, R extends Record<string, Type3<M, U, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & Record<string, Type3<M, U, L, any>> & {
sequenceSL: <U, L, R extends Record<string, Kind3<M, U, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & Record<string, Kind3<M, U, L, any>> & {
[K in keyof S]?: never;
}) => Do3C<M, S & {
[K in keyof R]: [R[K]] extends [Type3<M, any, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never;
}, U, L>;
return: <A, U, L>(f: (s: S) => A) => Type3<M, U, L, A>;
done: <U, L>() => Type3<M, U, L, S>;
return: <A, U, L>(f: (s: S) => A) => Kind3<M, U, L, A>;
done: <U, L>() => Kind3<M, U, L, S>;
}
export interface Do3C<M extends URIS3, S extends object, U, L> {
do: (ma: Type3<M, U, L, unknown>) => Do3C<M, S, U, L>;
doL: (f: (s: S) => Type3<M, U, L, unknown>) => Do3C<M, S, U, L>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Type3<M, U, L, A>) => Do3C<M, S & {
do: (ma: Kind3<M, U, L, unknown>) => Do3C<M, S, U, L>;
doL: (f: (s: S) => Kind3<M, U, L, unknown>) => Do3C<M, S, U, L>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Kind3<M, U, L, A>) => Do3C<M, S & {
[K in N]: A;
}, U, L>;
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Type3<M, U, L, A>) => Do3C<M, S & {
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Kind3<M, U, L, A>) => Do3C<M, S & {
[K in N]: A;
}, U, L>;
sequenceS: <R extends Record<string, Type3<M, U, L, any>>>(r: EnforceNonEmptyRecord<R> & {
sequenceS: <R extends Record<string, Kind3<M, U, L, any>>>(r: EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do3C<M, S & {
[K in keyof R]: [R[K]] extends [Type3<M, any, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never;
}, U, L>;
sequenceSL: <R extends Record<string, Type3<M, U, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
sequenceSL: <R extends Record<string, Kind3<M, U, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do3C<M, S & {
[K in keyof R]: [R[K]] extends [Type3<M, any, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind3<M, any, any, infer A>] ? A : never;
}, U, L>;
return: <A>(f: (s: S) => A) => Type3<M, U, L, A>;
done: () => Type3<M, U, L, S>;
return: <A>(f: (s: S) => A) => Kind3<M, U, L, A>;
done: () => Kind3<M, U, L, S>;
}
export interface Do2<M extends URIS2, S extends object> {
do: <L>(ma: Type2<M, L, unknown>) => Do2C<M, S, L>;
doL: <L>(f: (s: S) => Type2<M, L, unknown>) => Do2C<M, S, L>;
bind: <N extends string, A, L>(name: Exclude<N, keyof S>, ma: Type2<M, L, A>) => Do2C<M, S & {
do: <L>(ma: Kind2<M, L, unknown>) => Do2C<M, S, L>;
doL: <L>(f: (s: S) => Kind2<M, L, unknown>) => Do2C<M, S, L>;
bind: <N extends string, A, L>(name: Exclude<N, keyof S>, ma: Kind2<M, L, A>) => Do2C<M, S & {
[K in N]: A;
}, L>;
bindL: <N extends string, A, L>(name: Exclude<N, keyof S>, f: (s: S) => Type2<M, L, A>) => Do2C<M, S & {
bindL: <N extends string, A, L>(name: Exclude<N, keyof S>, f: (s: S) => Kind2<M, L, A>) => Do2C<M, S & {
[K in N]: A;
}, L>;
sequenceS: <L, R extends Record<string, Type2<M, L, any>>>(r: EnforceNonEmptyRecord<R> & Record<string, Type2<M, L, any>> & {
sequenceS: <L, R extends Record<string, Kind2<M, L, any>>>(r: EnforceNonEmptyRecord<R> & Record<string, Kind2<M, L, any>> & {
[K in keyof S]?: never;
}) => Do2C<M, S & {
[K in keyof R]: [R[K]] extends [Type2<M, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind2<M, any, infer A>] ? A : never;
}, L>;
sequenceSL: <L, R extends Record<string, Type2<M, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & Record<string, Type2<M, L, any>> & {
sequenceSL: <L, R extends Record<string, Kind2<M, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & Record<string, Kind2<M, L, any>> & {
[K in keyof S]?: never;
}) => Do2C<M, S & {
[K in keyof R]: [R[K]] extends [Type2<M, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind2<M, any, infer A>] ? A : never;
}, L>;
return: <A, L>(f: (s: S) => A) => Type2<M, L, A>;
done: <L>() => Type2<M, L, S>;
return: <A, L>(f: (s: S) => A) => Kind2<M, L, A>;
done: <L>() => Kind2<M, L, S>;
}
export interface Do2C<M extends URIS2, S extends object, L> {
do: (ma: Type2<M, L, unknown>) => Do2C<M, S, L>;
doL: (f: (s: S) => Type2<M, L, unknown>) => Do2C<M, S, L>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Type2<M, L, A>) => Do2C<M, S & {
do: (ma: Kind2<M, L, unknown>) => Do2C<M, S, L>;
doL: (f: (s: S) => Kind2<M, L, unknown>) => Do2C<M, S, L>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Kind2<M, L, A>) => Do2C<M, S & {
[K in N]: A;
}, L>;
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Type2<M, L, A>) => Do2C<M, S & {
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Kind2<M, L, A>) => Do2C<M, S & {
[K in N]: A;
}, L>;
sequenceS: <R extends Record<string, Type2<M, L, any>>>(r: EnforceNonEmptyRecord<R> & {
sequenceS: <R extends Record<string, Kind2<M, L, any>>>(r: EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do2C<M, S & {
[K in keyof R]: [R[K]] extends [Type2<M, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind2<M, any, infer A>] ? A : never;
}, L>;
sequenceSL: <R extends Record<string, Type2<M, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
sequenceSL: <R extends Record<string, Kind2<M, L, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do2C<M, S & {
[K in keyof R]: [R[K]] extends [Type2<M, any, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind2<M, any, infer A>] ? A : never;
}, L>;
return: <A>(f: (s: S) => A) => Type2<M, L, A>;
done: () => Type2<M, L, S>;
return: <A>(f: (s: S) => A) => Kind2<M, L, A>;
done: () => Kind2<M, L, S>;
}
export interface Do1<M extends URIS, S extends object> {
do: (ma: Type<M, unknown>) => Do1<M, S>;
doL: (f: (s: S) => Type<M, unknown>) => Do1<M, S>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Type<M, A>) => Do1<M, S & {
do: (ma: Kind<M, unknown>) => Do1<M, S>;
doL: (f: (s: S) => Kind<M, unknown>) => Do1<M, S>;
bind: <N extends string, A>(name: Exclude<N, keyof S>, ma: Kind<M, A>) => Do1<M, S & {
[K in N]: A;
}>;
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Type<M, A>) => Do1<M, S & {
bindL: <N extends string, A>(name: Exclude<N, keyof S>, f: (s: S) => Kind<M, A>) => Do1<M, S & {
[K in N]: A;
}>;
sequenceS: <R extends Record<string, Type<M, any>>>(r: EnforceNonEmptyRecord<R> & {
sequenceS: <R extends Record<string, Kind<M, any>>>(r: EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do1<M, S & {
[K in keyof R]: [R[K]] extends [Type<M, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind<M, infer A>] ? A : never;
}>;
sequenceSL: <R extends Record<string, Type<M, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
sequenceSL: <R extends Record<string, Kind<M, any>>>(f: (s: S) => EnforceNonEmptyRecord<R> & {
[K in keyof S]?: never;
}) => Do1<M, S & {
[K in keyof R]: [R[K]] extends [Type<M, infer A>] ? A : never;
[K in keyof R]: [R[K]] extends [Kind<M, infer A>] ? A : never;
}>;
return: <A>(f: (s: S) => A) => Type<M, A>;
done: () => Type<M, S>;
return: <A>(f: (s: S) => A) => Kind<M, A>;
done: () => Kind<M, S>;
}

@@ -160,3 +157,2 @@ export interface Do0<M, S extends object> {

export declare function Do<M extends URIS3>(M: Monad3<M>): Do3<M, {}>;
export declare function Do<M extends URIS3, U, L>(M: Monad3C<M, U, L>): Do3C<M, {}, U, L>;
export declare function Do<M extends URIS2>(M: Monad2<M>): Do2<M, {}>;

@@ -163,0 +159,0 @@ export declare function Do<M extends URIS2, L>(M: Monad2C<M, L>): Do2C<M, {}, L>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @file This module provides a simuation of Haskell do notation.
*/
var Apply_1 = require("fp-ts/lib/Apply");

@@ -4,0 +7,0 @@ var DoClass = /** @class */ (function () {

@@ -1,28 +0,53 @@

import { IO } from 'fp-ts/lib/IO';
import * as I from 'fp-ts/lib/IO';
import { Monad2 } from 'fp-ts/lib/Monad';
import { Reader } from 'fp-ts/lib/Reader';
import IO = I.IO;
declare module 'fp-ts/lib/HKT' {
interface URI2HKT2<L, A> {
ReaderIO: ReaderIO<L, A>;
interface URItoKind2<E, A> {
ReaderIO: ReaderIO<E, A>;
}
}
/**
* @since 0.1.0
*/
export declare const URI = "ReaderIO";
/**
* @since 0.1.0
*/
export declare type URI = typeof URI;
export declare class ReaderIO<E, A> {
readonly run: (e: E) => IO<A>;
readonly _A: A;
readonly _L: E;
readonly _URI: URI;
constructor(run: (e: E) => IO<A>);
map<B>(f: (a: A) => B): ReaderIO<E, B>;
of<E, B>(b: B): ReaderIO<E, B>;
ap<B>(fab: ReaderIO<E, (a: A) => B>): ReaderIO<E, B>;
ap_<B, C>(this: ReaderIO<E, (b: B) => C>, fb: ReaderIO<E, B>): ReaderIO<E, C>;
chain<B>(f: (a: A) => ReaderIO<E, B>): ReaderIO<E, B>;
/**
* @since 0.1.0
*/
export interface ReaderIO<R, A> {
(r: R): IO<A>;
}
export declare const ask: <E>() => ReaderIO<E, E>;
export declare const asks: <E, A>(f: (e: E) => A) => ReaderIO<E, A>;
export declare const local: <E>(f: (e: E) => E) => <A>(fa: ReaderIO<E, A>) => ReaderIO<E, A>;
export declare const fromIO: <E, A>(fa: IO<A>) => ReaderIO<E, A>;
export declare const fromReader: <E, A>(fa: Reader<E, A>) => ReaderIO<E, A>;
/**
* @since 0.1.0
*/
export declare function run<R, A>(ma: ReaderIO<R, A>, r: R): A;
/**
* @since 0.1.0
*/
export declare const fromReader: <R, A>(ma: Reader<R, A>) => ReaderIO<R, A>;
/**
* @since 0.1.0
*/
export declare const fromIO: <R, A>(ma: IO<A>) => ReaderIO<R, A>;
/**
* @since 0.1.0
*/
export declare const ask: <R>() => ReaderIO<R, R>;
/**
* @since 0.1.0
*/
export declare const asks: <R, A>(f: (r: R) => A) => ReaderIO<R, A>;
/**
* @since 0.1.0
*/
export declare function local<Q, R>(f: (f: Q) => R): <A>(ma: ReaderIO<R, A>) => ReaderIO<Q, A>;
/**
* @since 0.1.0
*/
export declare const readerIO: Monad2<URI>;
declare const ap: <E, A>(fa: ReaderIO<E, A>) => <B>(fab: ReaderIO<E, (a: A) => B>) => ReaderIO<E, B>, apFirst: <E, B>(fb: ReaderIO<E, B>) => <A>(fa: ReaderIO<E, A>) => ReaderIO<E, A>, apSecond: <e, B>(fb: ReaderIO<e, B>) => <A>(fa: ReaderIO<e, A>) => ReaderIO<e, B>, chain: <E, A, B>(f: (a: A) => ReaderIO<E, B>) => (ma: ReaderIO<E, A>) => ReaderIO<E, B>, chainFirst: <E, A, B>(f: (a: A) => ReaderIO<E, B>) => (ma: ReaderIO<E, A>) => ReaderIO<E, A>, flatten: <E, A>(mma: ReaderIO<E, ReaderIO<E, A>>) => ReaderIO<E, A>, map: <A, B>(f: (a: A) => B) => <E>(fa: ReaderIO<E, A>) => ReaderIO<E, B>;
export { ap, apFirst, apSecond, chain, chainFirst, flatten, map };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var IO_1 = require("fp-ts/lib/IO");
var readerT = require("fp-ts/lib/ReaderT");
var readerTIO = readerT.getReaderT2v(IO_1.io);
var I = require("fp-ts/lib/IO");
var pipeable_1 = require("fp-ts/lib/pipeable");
var ReaderT_1 = require("fp-ts/lib/ReaderT");
var T = ReaderT_1.getReaderM(I.io);
/**
* @since 0.1.0
*/
exports.URI = 'ReaderIO';
var ReaderIO = /** @class */ (function () {
function ReaderIO(run) {
this.run = run;
}
ReaderIO.prototype.map = function (f) {
return new ReaderIO(readerTIO.map(this.run, f));
};
ReaderIO.prototype.of = function (b) {
return of(b);
};
ReaderIO.prototype.ap = function (fab) {
return new ReaderIO(readerTIO.ap(fab.run, this.run));
};
ReaderIO.prototype.ap_ = function (fb) {
return fb.ap(this);
};
ReaderIO.prototype.chain = function (f) {
return new ReaderIO(readerTIO.chain(this.run, function (a) { return f(a).run; }));
};
return ReaderIO;
}());
exports.ReaderIO = ReaderIO;
var map = function (fa, f) {
return fa.map(f);
};
var of = function (a) {
return new ReaderIO(readerTIO.of(a));
};
var ap = function (fab, fa) {
return fa.ap(fab);
};
var chain = function (fa, f) {
return fa.chain(f);
};
exports.ask = function () {
return new ReaderIO(IO_1.io.of);
};
exports.asks = function (f) {
return new ReaderIO(function (e) { return IO_1.io.of(f(e)); });
};
exports.local = function (f) { return function (fa) {
return new ReaderIO(function (e) { return fa.run(f(e)); });
}; };
exports.fromIO = function (fa) {
return new ReaderIO(function () { return fa; });
};
var readerTfromReader = readerT.fromReader(IO_1.io);
exports.fromReader = function (fa) {
return new ReaderIO(readerTfromReader(fa));
};
/**
* @since 0.1.0
*/
function run(ma, r) {
return ma(r)();
}
exports.run = run;
/**
* @since 0.1.0
*/
exports.fromReader = T.fromReader;
/**
* @since 0.1.0
*/
exports.fromIO = T.fromM;
/**
* @since 0.1.0
*/
exports.ask = T.ask;
/**
* @since 0.1.0
*/
exports.asks = T.asks;
/**
* @since 0.1.0
*/
function local(f) {
return function (ma) { return T.local(ma, f); };
}
exports.local = local;
/**
* @since 0.1.0
*/
exports.readerIO = {
URI: exports.URI,
map: map,
of: of,
ap: ap,
chain: chain
map: T.map,
of: T.of,
ap: T.ap,
chain: T.chain
};
var _a = pipeable_1.pipeable(exports.readerIO), ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map;
exports.ap = ap;
exports.apFirst = apFirst;
exports.apSecond = apSecond;
exports.chain = chain;
exports.chainFirst = chainFirst;
exports.flatten = flatten;
exports.map = map;

@@ -17,4 +17,4 @@ /**

*/
import { Functor, Functor1, Functor2, Functor2C, Functor3, Functor3C } from 'fp-ts/lib/Functor';
import { HKT, Type, Type2, Type3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { Functor, Functor1, Functor2, Functor2C, Functor3 } from 'fp-ts/lib/Functor';
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { These } from 'fp-ts/lib/These';

@@ -28,21 +28,29 @@ /**

}
/**
* @since 0.3.0
*/
export interface Semialign1<F extends URIS> extends Functor1<F> {
readonly align: <A, B>(fa: Type<F, A>, fb: Type<F, B>) => Type<F, These<A, B>>;
readonly alignWith: <A, B, C>(fa: Type<F, A>, fb: Type<F, B>, f: (x: These<A, B>) => C) => Type<F, C>;
readonly align: <A, B>(fa: Kind<F, A>, fb: Kind<F, B>) => Kind<F, These<A, B>>;
readonly alignWith: <A, B, C>(fa: Kind<F, A>, fb: Kind<F, B>, f: (x: These<A, B>) => C) => Kind<F, C>;
}
/**
* @since 0.3.0
*/
export interface Semialign2<F extends URIS2> extends Functor2<F> {
readonly align: <L, A, B>(fa: Type2<F, L, A>, fb: Type2<F, L, B>) => Type2<F, L, These<A, B>>;
readonly alignWith: <L, A, B, C>(fa: Type2<F, L, A>, fb: Type2<F, L, B>, f: (x: These<A, B>) => C) => Type2<F, L, C>;
readonly align: <L, A, B>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>) => Kind2<F, L, These<A, B>>;
readonly alignWith: <L, A, B, C>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>, f: (x: These<A, B>) => C) => Kind2<F, L, C>;
}
export interface Semialign3<F extends URIS3> extends Functor3<F> {
readonly align: <U, L, A, B>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>) => Type3<F, U, L, These<A, B>>;
readonly alignWith: <U, L, A, B, C>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>, f: (x: These<A, B>) => C) => Type3<F, U, L, C>;
}
/**
* @since 0.3.0
*/
export interface Semialign2C<F extends URIS2, L> extends Functor2C<F, L> {
readonly align: <A, B>(fa: Type2<F, L, A>, fb: Type2<F, L, B>) => Type2<F, L, These<A, B>>;
readonly alignWith: <A, B, C>(fa: Type2<F, L, A>, fb: Type2<F, L, B>, f: (x: These<A, B>) => C) => Type2<F, L, C>;
readonly align: <A, B>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>) => Kind2<F, L, These<A, B>>;
readonly alignWith: <A, B, C>(fa: Kind2<F, L, A>, fb: Kind2<F, L, B>, f: (x: These<A, B>) => C) => Kind2<F, L, C>;
}
export interface Semialign3C<F extends URIS3, U, L> extends Functor3C<F, U, L> {
readonly align: <A, B>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>) => Type3<F, U, L, These<A, B>>;
readonly alignWith: <A, B, C>(fa: Type3<F, U, L, A>, fb: Type3<F, U, L, B>, f: (x: These<A, B>) => C) => Type3<F, U, L, C>;
/**
* @since 0.3.0
*/
export interface Semialign3<F extends URIS3> extends Functor3<F> {
readonly align: <U, L, A, B>(fa: Kind3<F, U, L, A>, fb: Kind3<F, U, L, B>) => Kind3<F, U, L, These<A, B>>;
readonly alignWith: <U, L, A, B, C>(fa: Kind3<F, U, L, A>, fb: Kind3<F, U, L, B>, f: (x: These<A, B>) => C) => Kind3<F, U, L, C>;
}

@@ -32,3 +32,3 @@ "use strict";

alignWith: function (fa, fb, f) {
return new NonEmptyArray_1.NonEmptyArray(f(These_1.both(fa.head, fb.head)), Array_1.alignArray.alignWith(fa.tail, fb.tail, f));
return NonEmptyArray_1.cons(f(These_1.both(NonEmptyArray_1.head(fa), NonEmptyArray_1.head(fb))), Array_1.alignArray.alignWith(NonEmptyArray_1.tail(fa), NonEmptyArray_1.tail(fb), f));
},

@@ -50,4 +50,4 @@ /**

align: function (fa, fb) {
return new NonEmptyArray_1.NonEmptyArray(These_1.both(fa.head, fb.head), Array_1.alignArray.align(fa.tail, fb.tail));
return NonEmptyArray_1.cons(These_1.both(NonEmptyArray_1.head(fa), NonEmptyArray_1.head(fb)), Array_1.alignArray.align(NonEmptyArray_1.tail(fa), NonEmptyArray_1.tail(fb)));
}
};

@@ -1,32 +0,65 @@

import { Endomorphism } from 'fp-ts/lib/function';
import { IO } from 'fp-ts/lib/IO';
import * as I from 'fp-ts/lib/IO';
import { Monad2 } from 'fp-ts/lib/Monad';
import { State } from 'fp-ts/lib/State';
import IO = I.IO;
declare module 'fp-ts/lib/HKT' {
interface URI2HKT2<L, A> {
StateIO: StateIO<L, A>;
interface URItoKind2<E, A> {
StateIO: StateIO<E, A>;
}
}
/**
* @since 0.1.0
*/
export declare const URI = "StateIO";
/**
* @since 0.1.0
*/
export declare type URI = typeof URI;
export declare class StateIO<S, A> {
readonly value: (s: S) => IO<[A, S]>;
readonly _A: A;
readonly _L: S;
readonly _URI: URI;
constructor(value: (s: S) => IO<[A, S]>);
run(s: S): [A, S];
eval(s: S): A;
exec(s: S): S;
map<B>(f: (a: A) => B): StateIO<S, B>;
ap<B>(fab: StateIO<S, (a: A) => B>): StateIO<S, B>;
ap_<B, C>(this: StateIO<S, (b: B) => C>, fb: StateIO<S, B>): StateIO<S, C>;
chain<B>(f: (a: A) => StateIO<S, B>): StateIO<S, B>;
/**
* @since 0.1.0
*/
export interface StateIO<S, A> {
(s: S): IO<[A, S]>;
}
/**
* @since 0.1.0
*/
export declare function run<S, A>(ma: StateIO<S, A>, s: S): A;
/**
* @since 0.1.0
*/
export declare const evalState: <S, A>(ma: StateIO<S, A>, s: S) => IO<A>;
/**
* @since 0.1.0
*/
export declare const execState: <S, A>(ma: StateIO<S, A>, s: S) => IO<S>;
/**
* @since 0.1.0
*/
export declare const fromIO: <S, A>(ma: IO<A>) => StateIO<S, A>;
/**
* @since 0.1.0
*/
export declare const fromState: <S, A>(ma: State<S, A>) => StateIO<S, A>;
/**
* @since 0.1.0
*/
export declare const get: <S>() => StateIO<S, S>;
/**
* @since 0.1.0
*/
export declare const put: <S>(s: S) => StateIO<S, void>;
export declare const modify: <S>(f: Endomorphism<S>) => StateIO<S, void>;
/**
* @since 0.1.0
*/
export declare const modify: <S>(f: (s: S) => S) => StateIO<S, void>;
/**
* @since 0.1.0
*/
export declare const gets: <S, A>(f: (s: S) => A) => StateIO<S, A>;
export declare const fromIO: <S, A>(fa: IO<A>) => StateIO<S, A>;
export declare const fromState: <S, A>(fa: State<S, A>) => StateIO<S, A>;
/**
* @since 0.1.0
*/
export declare const stateIO: Monad2<URI>;
declare const ap: <E, A>(fa: StateIO<E, A>) => <B>(fab: StateIO<E, (a: A) => B>) => StateIO<E, B>, apFirst: <E, B>(fb: StateIO<E, B>) => <A>(fa: StateIO<E, A>) => StateIO<E, A>, apSecond: <e, B>(fb: StateIO<e, B>) => <A>(fa: StateIO<e, A>) => StateIO<e, B>, chain: <E, A, B>(f: (a: A) => StateIO<E, B>) => (ma: StateIO<E, A>) => StateIO<E, B>, chainFirst: <E, A, B>(f: (a: A) => StateIO<E, B>) => (ma: StateIO<E, A>) => StateIO<E, A>, flatten: <E, A>(mma: StateIO<E, StateIO<E, A>>) => StateIO<E, A>, map: <A, B>(f: (a: A) => B) => <E>(fa: StateIO<E, A>) => StateIO<E, B>;
export { ap, apFirst, apSecond, chain, chainFirst, flatten, map };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var function_1 = require("fp-ts/lib/function");
var IO_1 = require("fp-ts/lib/IO");
var stateT = require("fp-ts/lib/StateT");
var stateTIO = stateT.getStateT2v(IO_1.io);
var I = require("fp-ts/lib/IO");
var StateT_1 = require("fp-ts/lib/StateT");
var pipeable_1 = require("fp-ts/lib/pipeable");
var T = StateT_1.getStateM(I.io);
/**
* @since 0.1.0
*/
exports.URI = 'StateIO';
var StateIO = /** @class */ (function () {
function StateIO(value) {
this.value = value;
}
StateIO.prototype.run = function (s) {
return this.value(s).run();
};
StateIO.prototype.eval = function (s) {
return this.run(s)[0];
};
StateIO.prototype.exec = function (s) {
return this.run(s)[1];
};
StateIO.prototype.map = function (f) {
return new StateIO(stateTIO.map(this.value, f));
};
StateIO.prototype.ap = function (fab) {
return new StateIO(stateTIO.ap(fab.value, this.value));
};
StateIO.prototype.ap_ = function (fb) {
return fb.ap(this);
};
StateIO.prototype.chain = function (f) {
return new StateIO(stateTIO.chain(this.value, function (a) { return f(a).value; }));
};
return StateIO;
}());
exports.StateIO = StateIO;
var map = function (fa, f) {
return fa.map(f);
};
var of = function (a) {
return new StateIO(stateTIO.of(a));
};
var ap = function (fab, fa) {
return fa.ap(fab);
};
var chain = function (fa, f) {
return fa.chain(f);
};
exports.get = function () {
return new StateIO(function (s) { return IO_1.io.of(function_1.tuple(s, s)); });
};
var stateTput = stateT.put(IO_1.io);
exports.put = function (s) {
return new StateIO(stateTput(s));
};
var stateTmodify = stateT.modify(IO_1.io);
exports.modify = function (f) {
return new StateIO(stateTmodify(f));
};
var stateTgets = stateT.gets(IO_1.io);
exports.gets = function (f) {
return new StateIO(stateTgets(f));
};
var stateTliftF = stateT.liftF(IO_1.io);
exports.fromIO = function (fa) {
return new StateIO(stateTliftF(fa));
};
var stateTfromState = stateT.fromState(IO_1.io);
exports.fromState = function (fa) {
return new StateIO(stateTfromState(fa));
};
/**
* @since 0.1.0
*/
function run(ma, s) {
return ma(s)()[0];
}
exports.run = run;
/**
* @since 0.1.0
*/
exports.evalState = T.evalState;
/**
* @since 0.1.0
*/
exports.execState = T.execState;
/**
* @since 0.1.0
*/
exports.fromIO = T.fromM;
/**
* @since 0.1.0
*/
exports.fromState = T.fromState;
/**
* @since 0.1.0
*/
exports.get = T.get;
/**
* @since 0.1.0
*/
exports.put = T.put;
/**
* @since 0.1.0
*/
exports.modify = T.modify;
/**
* @since 0.1.0
*/
exports.gets = T.gets;
/**
* @since 0.1.0
*/
exports.stateIO = {
URI: exports.URI,
map: map,
of: of,
ap: ap,
chain: chain
map: T.map,
of: T.of,
ap: T.ap,
chain: T.chain
};
var _a = pipeable_1.pipeable(exports.stateIO), ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map;
exports.ap = ap;
exports.apFirst = apFirst;
exports.apSecond = apSecond;
exports.chain = chain;
exports.chainFirst = chainFirst;
exports.flatten = flatten;
exports.map = map;
import { Either } from 'fp-ts/lib/Either';
import { IO } from 'fp-ts/lib/IO';
import { IOEither } from 'fp-ts/lib/IOEither';
import { Monad3 } from 'fp-ts/lib/Monad';
import { MonadThrow3 } from 'fp-ts/lib/MonadThrow';
import { State } from 'fp-ts/lib/State';
import { TaskEither } from 'fp-ts/lib/TaskEither';
import { Endomorphism } from 'fp-ts/lib/function';
import { Task } from 'fp-ts/lib/Task';
import * as TE from 'fp-ts/lib/TaskEither';
import TaskEither = TE.TaskEither;
declare module 'fp-ts/lib/HKT' {
interface URI2HKT3<U, L, A> {
StateTaskEither: StateTaskEither<U, L, A>;
interface URItoKind3<R, E, A> {
StateTaskEither: StateTaskEither<R, E, A>;
}
}
/**
* @since 0.1.0
*/
export declare const URI = "StateTaskEither";
/**
* @since 0.1.0
*/
export declare type URI = typeof URI;
export declare class StateTaskEither<S, L, A> {
readonly value: (s: S) => TaskEither<L, [A, S]>;
readonly _A: A;
readonly _L: L;
readonly _U: S;
readonly _URI: URI;
constructor(value: (s: S) => TaskEither<L, [A, S]>);
run(s: S): Promise<Either<L, [A, S]>>;
eval(s: S): Promise<Either<L, A>>;
exec(s: S): Promise<Either<L, S>>;
map<B>(f: (a: A) => B): StateTaskEither<S, L, B>;
ap<B>(fab: StateTaskEither<S, L, (a: A) => B>): StateTaskEither<S, L, B>;
ap_<B, C>(this: StateTaskEither<S, L, (b: B) => C>, fb: StateTaskEither<S, L, B>): StateTaskEither<S, L, C>;
chain<B>(f: (a: A) => StateTaskEither<S, L, B>): StateTaskEither<S, L, B>;
orElse<M>(f: (l: L) => StateTaskEither<S, M, A>): StateTaskEither<S, M, A>;
/**
* @since 0.1.0
*/
export interface StateTaskEither<S, E, A> {
(s: S): TaskEither<E, [A, S]>;
}
export declare const get: <L, S>() => StateTaskEither<S, L, S>;
export declare const put: <L, S>(s: S) => StateTaskEither<S, L, void>;
export declare const modify: <L, S>(f: Endomorphism<S>) => StateTaskEither<S, L, void>;
export declare const gets: <S, L, A>(f: (s: S) => A) => StateTaskEither<S, L, A>;
export declare const fromTaskEither: <S, L, A>(fa: TaskEither<L, A>) => StateTaskEither<S, L, A>;
export declare const fromState: <S, A, L>(fa: State<S, A>) => StateTaskEither<S, L, A>;
export declare const stateTaskEither: Monad3<URI>;
/**
* @since 0.1.0
*/
export declare function run<S, E, A>(ma: StateTaskEither<S, E, A>, s: S): Promise<Either<E, [A, S]>>;
/**
* @since 0.1.0
*/
export declare const evalState: <S, E, A>(ma: StateTaskEither<S, E, A>, s: S) => TaskEither<E, A>;
/**
* @since 0.1.0
*/
export declare const execState: <S, E, A>(ma: StateTaskEither<S, E, A>, s: S) => TaskEither<E, S>;
/**
* @since 0.1.0
*/
export declare function left<S, E>(e: E): StateTaskEither<S, E, never>;
/**
* @since 0.1.0
*/
export declare const right: <S, A>(a: A) => StateTaskEither<S, never, A>;
/**
* @since 0.1.0
*/
export declare function rightTask<S, A>(ma: Task<A>): StateTaskEither<S, never, A>;
/**
* @since 0.1.0
*/
export declare function leftTask<S, E>(me: Task<E>): StateTaskEither<S, E, never>;
/**
* @since 0.1.0
*/
export declare const fromTaskEither: <S, E, A>(ma: TaskEither<E, A>) => StateTaskEither<S, E, A>;
/**
* @since 0.1.0
*/
export declare function fromIOEither<S, E, A>(ma: IOEither<E, A>): StateTaskEither<S, E, A>;
/**
* @since 0.1.0
*/
export declare function rightIO<S, A>(ma: IO<A>): StateTaskEither<S, never, A>;
/**
* @since 0.1.0
*/
export declare function leftIO<S, E>(me: IO<E>): StateTaskEither<S, E, never>;
/**
* @since 0.1.0
*/
export declare const rightState: <S, A>(ma: State<S, A>) => StateTaskEither<S, never, A>;
/**
* @since 0.1.0
*/
export declare function leftState<S, E>(me: State<S, E>): StateTaskEither<S, E, never>;
/**
* @since 0.1.0
*/
export declare const get: <S>() => StateTaskEither<S, never, S>;
/**
* @since 0.1.0
*/
export declare const put: <S>(s: S) => StateTaskEither<S, never, void>;
/**
* @since 0.1.0
*/
export declare const modify: <S>(f: (s: S) => S) => StateTaskEither<S, never, void>;
/**
* @since 0.1.0
*/
export declare const gets: <S, A>(f: (s: S) => A) => StateTaskEither<S, never, A>;
/**
* @since 0.1.0
*/
export declare const stateTaskEither: Monad3<URI> & MonadThrow3<URI>;
/**
* Like `stateTaskEither` but `ap` is sequential
* @since 0.1.0
*/
export declare const stateTaskEitherSeq: typeof stateTaskEither;
declare const ap: <R, E, A>(fa: StateTaskEither<R, E, A>) => <B>(fab: StateTaskEither<R, E, (a: A) => B>) => StateTaskEither<R, E, B>, apFirst: <R, E, B>(fb: StateTaskEither<R, E, B>) => <A>(fa: StateTaskEither<R, E, A>) => StateTaskEither<R, E, A>, apSecond: <R, E, B>(fb: StateTaskEither<R, E, B>) => <A>(fa: StateTaskEither<R, E, A>) => StateTaskEither<R, E, B>, chain: <R, E, A, B>(f: (a: A) => StateTaskEither<R, E, B>) => (ma: StateTaskEither<R, E, A>) => StateTaskEither<R, E, B>, chainFirst: <R, E, A, B>(f: (a: A) => StateTaskEither<R, E, B>) => (ma: StateTaskEither<R, E, A>) => StateTaskEither<R, E, A>, flatten: <R, E, A>(mma: StateTaskEither<R, E, StateTaskEither<R, E, A>>) => StateTaskEither<R, E, A>, map: <A, B>(f: (a: A) => B) => <R, E>(fa: StateTaskEither<R, E, A>) => StateTaskEither<R, E, B>, filterOrElse: {
<E, A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>, onFalse: (a: A) => E): <R>(ma: StateTaskEither<R, E, A>) => StateTaskEither<R, E, B>;
<E, A>(predicate: import("fp-ts/lib/function").Predicate<A>, onFalse: (a: A) => E): <R>(ma: StateTaskEither<R, E, A>) => StateTaskEither<R, E, A>;
}, fromEither: <R, E, A>(ma: Either<E, A>) => StateTaskEither<R, E, A>, fromOption: <E>(onNone: () => E) => <R, A>(ma: import("fp-ts/lib/Option").Option<A>) => StateTaskEither<R, E, A>, fromPredicate: {
<E, A, B extends A>(refinement: import("fp-ts/lib/function").Refinement<A, B>, onFalse: (a: A) => E): <U>(a: A) => StateTaskEither<U, E, B>;
<E, A>(predicate: import("fp-ts/lib/function").Predicate<A>, onFalse: (a: A) => E): <R>(a: A) => StateTaskEither<R, E, A>;
};
export { ap, apFirst, apSecond, chain, chainFirst, flatten, map, filterOrElse, fromEither, fromOption, fromPredicate };
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var stateT = require("fp-ts/lib/StateT");
var TaskEither_1 = require("fp-ts/lib/TaskEither");
var T = stateT.getStateT2v(TaskEither_1.taskEither);
var StateT_1 = require("fp-ts/lib/StateT");
var TE = require("fp-ts/lib/TaskEither");
var pipeable_1 = require("fp-ts/lib/pipeable");
var T = StateT_1.getStateM(TE.taskEither);
/**
* @since 0.1.0
*/
exports.URI = 'StateTaskEither';
var StateTaskEither = /** @class */ (function () {
function StateTaskEither(value) {
this.value = value;
}
StateTaskEither.prototype.run = function (s) {
return this.value(s).run();
};
StateTaskEither.prototype.eval = function (s) {
return this.run(s).then(function (e) { return e.map(function (_a) {
var a = _a[0];
return a;
}); });
};
StateTaskEither.prototype.exec = function (s) {
return this.run(s).then(function (e) { return e.map(function (_a) {
var _ = _a[0], s = _a[1];
return s;
}); });
};
StateTaskEither.prototype.map = function (f) {
return new StateTaskEither(T.map(this.value, f));
};
StateTaskEither.prototype.ap = function (fab) {
return new StateTaskEither(T.ap(fab.value, this.value));
};
StateTaskEither.prototype.ap_ = function (fb) {
return fb.ap(this);
};
StateTaskEither.prototype.chain = function (f) {
return new StateTaskEither(T.chain(this.value, function (a) { return f(a).value; }));
};
StateTaskEither.prototype.orElse = function (f) {
var _this = this;
return new StateTaskEither(function (s) { return _this.value(s).orElse(function (l) { return f(l).value(s); }); });
};
return StateTaskEither;
}());
exports.StateTaskEither = StateTaskEither;
var map = function (fa, f) { return fa.map(f); };
var of = function (a) { return new StateTaskEither(T.of(a)); };
var ap = function (fab, fa) { return fa.ap(fab); };
var chain = function (fa, f) { return fa.chain(f); };
var getT = stateT.get2v(TaskEither_1.taskEither);
exports.get = function () { return new StateTaskEither(getT); };
var putT = stateT.put(TaskEither_1.taskEither);
exports.put = function (s) {
return new StateTaskEither(putT(s));
};
var modifyT = stateT.modify(TaskEither_1.taskEither);
exports.modify = function (f) {
return new StateTaskEither(modifyT(f));
};
var getsT = stateT.gets(TaskEither_1.taskEither);
exports.gets = function (f) {
return new StateTaskEither(getsT(f));
};
var liftT = stateT.liftF(TaskEither_1.taskEither);
exports.fromTaskEither = function (fa) {
return new StateTaskEither(liftT(fa));
};
var fromStateT = stateT.fromState(TaskEither_1.taskEither);
exports.fromState = function (fa) {
return new StateTaskEither(fromStateT(fa));
};
/**
* @since 0.1.0
*/
function run(ma, s) {
return ma(s)();
}
exports.run = run;
/**
* @since 0.1.0
*/
exports.evalState = T.evalState;
/**
* @since 0.1.0
*/
exports.execState = T.execState;
/**
* @since 0.1.0
*/
function left(e) {
return exports.fromTaskEither(TE.left(e));
}
exports.left = left;
/**
* @since 0.1.0
*/
exports.right = T.of;
/**
* @since 0.1.0
*/
function rightTask(ma) {
return exports.fromTaskEither(TE.rightTask(ma));
}
exports.rightTask = rightTask;
/**
* @since 0.1.0
*/
function leftTask(me) {
return exports.fromTaskEither(TE.leftTask(me));
}
exports.leftTask = leftTask;
/**
* @since 0.1.0
*/
exports.fromTaskEither = T.fromM;
/**
* @since 0.1.0
*/
function fromIOEither(ma) {
return exports.fromTaskEither(TE.fromIOEither(ma));
}
exports.fromIOEither = fromIOEither;
/**
* @since 0.1.0
*/
function rightIO(ma) {
return exports.fromTaskEither(TE.rightIO(ma));
}
exports.rightIO = rightIO;
/**
* @since 0.1.0
*/
function leftIO(me) {
return exports.fromTaskEither(TE.leftIO(me));
}
exports.leftIO = leftIO;
/**
* @since 0.1.0
*/
exports.rightState = T.fromState;
/**
* @since 0.1.0
*/
function leftState(me) {
return function (s) { return TE.left(me(s)[0]); };
}
exports.leftState = leftState;
/**
* @since 0.1.0
*/
exports.get = T.get;
/**
* @since 0.1.0
*/
exports.put = T.put;
/**
* @since 0.1.0
*/
exports.modify = T.modify;
/**
* @since 0.1.0
*/
exports.gets = T.gets;
/**
* @since 0.1.0
*/
exports.stateTaskEither = {
URI: exports.URI,
map: map,
of: of,
ap: ap,
chain: chain
map: T.map,
of: exports.right,
ap: T.ap,
chain: T.chain,
throwError: left
};
/**
* Like `stateTaskEither` but `ap` is sequential
* @since 0.1.0
*/
exports.stateTaskEitherSeq = __assign({}, exports.stateTaskEither, { ap: function (mab, ma) { return T.chain(mab, function (f) { return T.map(ma, f); }); } });
var _a = pipeable_1.pipeable(exports.stateTaskEither), ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map, filterOrElse = _a.filterOrElse, fromEither = _a.fromEither, fromOption = _a.fromOption, fromPredicate = _a.fromPredicate;
exports.ap = ap;
exports.apFirst = apFirst;
exports.apSecond = apSecond;
exports.chain = chain;
exports.chainFirst = chainFirst;
exports.flatten = flatten;
exports.map = map;
exports.filterOrElse = filterOrElse;
exports.fromEither = fromEither;
exports.fromOption = fromOption;
exports.fromPredicate = fromPredicate;

@@ -7,11 +7,17 @@ import { Task } from 'fp-ts/lib/Task';

* import { withTimeout } from 'fp-ts-contrib/lib/Task/withTimeout'
* import { delay } from 'fp-ts/lib/Task'
* import { delay, of } from 'fp-ts/lib/Task'
*
* const completeAfter2s = delay(2000, 'result')
* const completeAfter2s = delay(2000)(of('result'))
*
* withTimeout(completeAfter2s, 'timeout', 3000).run() // Promise('result')
* withTimeout(completeAfter2s, 'timeout', 1000).run() // Promise('timeout')
* async function f() {
* const a1 = await withTimeout('timeout', 3000)(completeAfter2s)()
* assert.strictEqual(a1, 'result')
* const a2 = await withTimeout('timeout', 1000)(completeAfter2s)()
* assert.strictEqual(a2, 'timeout')
* }
*
* @since 0.0.6
* f()
*
* @since 0.1.0
*/
export declare const withTimeout: <A>(t: Task<A>, onTimeout: A, millis: number) => Task<A>;
export declare function withTimeout<A>(onTimeout: A, millis: number): (ma: Task<A>) => Task<A>;

@@ -9,14 +9,22 @@ "use strict";

* import { withTimeout } from 'fp-ts-contrib/lib/Task/withTimeout'
* import { delay } from 'fp-ts/lib/Task'
* import { delay, of } from 'fp-ts/lib/Task'
*
* const completeAfter2s = delay(2000, 'result')
* const completeAfter2s = delay(2000)(of('result'))
*
* withTimeout(completeAfter2s, 'timeout', 3000).run() // Promise('result')
* withTimeout(completeAfter2s, 'timeout', 1000).run() // Promise('timeout')
* async function f() {
* const a1 = await withTimeout('timeout', 3000)(completeAfter2s)()
* assert.strictEqual(a1, 'result')
* const a2 = await withTimeout('timeout', 1000)(completeAfter2s)()
* assert.strictEqual(a2, 'timeout')
* }
*
* @since 0.0.6
* f()
*
* @since 0.1.0
*/
exports.withTimeout = function (t, onTimeout, millis) {
var timeoutTask = Task_1.delay(millis, onTimeout);
return Task_1.getRaceMonoid().concat(t, timeoutTask);
};
function withTimeout(onTimeout, millis) {
var M = Task_1.getRaceMonoid();
var fallback = Task_1.delay(millis)(Task_1.of(onTimeout));
return function (ma) { return M.concat(ma, fallback); };
}
exports.withTimeout = withTimeout;

@@ -0,47 +1,52 @@

import { Alt1 } from 'fp-ts/lib/Alt';
import { Task } from 'fp-ts/lib/Task';
import { Monad1 } from 'fp-ts/lib/Monad';
import { Option } from 'fp-ts/lib/Option';
import { Task } from 'fp-ts/lib/Task';
import { Lazy } from 'fp-ts/lib/function';
declare module 'fp-ts/lib/HKT' {
interface URI2HKT<A> {
interface URItoKind<A> {
TaskOption: TaskOption<A>;
}
}
/**
* @since 0.1.0
*/
export declare const URI = "TaskOption";
/**
* @since 0.1.0
*/
export declare type URI = typeof URI;
export declare class TaskOption<A> {
readonly value: Task<Option<A>>;
readonly _A: A;
readonly _URI: URI;
constructor(value: Task<Option<A>>);
run(): Promise<Option<A>>;
map<B>(f: (a: A) => B): TaskOption<B>;
ap<B>(fab: TaskOption<(a: A) => B>): TaskOption<B>;
ap_<B, C>(this: TaskOption<(b: B) => C>, fb: TaskOption<B>): TaskOption<C>;
chain<B>(f: (a: A) => TaskOption<B>): TaskOption<B>;
fold<R>(onNone: R, onSome: (a: A) => R): Task<R>;
getOrElse(a: A): Task<A>;
/**
* @since 0.1.0
*/
export interface TaskOption<A> extends Task<Option<A>> {
}
export declare const some: <A>(a: A) => TaskOption<A>;
export declare const none: TaskOption<never>;
/**
* @since 0.1.0
*/
export declare const fromTask: <A>(as: Task<A>) => TaskOption<A>;
/**
* @since 0.1.0
*/
export declare const fromOption: <A>(ma: Option<A>) => TaskOption<A>;
export declare const fromTask: <A>(ma: Task<A>) => TaskOption<A>;
export declare const tryCatch: <A>(f: Lazy<Promise<A>>) => TaskOption<A>;
/**
* Returns the `TaskOption` result if it completes within a timeout, or a fallback value instead.
*
* @example
* import { TaskOption, withTimeout } from 'fp-ts-contrib/lib/TaskOption'
* import { delay } from 'fp-ts/lib/Task'
* import { some, none } from 'fp-ts/lib/Option'
*
* const completeAfter2s = new TaskOption(delay(2000, some('result')))
*
* withTimeout(completeAfter2s, some('timeout'), 3000).run() // Promise(some('result'))
* withTimeout(completeAfter2s, none, 1000).run() // Promise(none)
* withTimeout(completeAfter2s, some('timeout'), 1000).run() // Promise(some('timeout'))
*
* @since 0.0.6
* @since 0.1.0
*/
export declare const withTimeout: <A>(fa: TaskOption<A>, onTimeout: Option<A>, millis: number) => TaskOption<A>;
export declare const taskOption: Monad1<URI>;
export declare const none: TaskOption<never>;
/**
* @since 0.1.0
*/
export declare const some: <A>(a: A) => TaskOption<A>;
/**
* @since 0.1.0
*/
export declare function fold<A, B>(onNone: () => Task<B>, onSome: (a: A) => Task<B>): (as: TaskOption<A>) => Task<B>;
/**
* @since 0.1.0
*/
export declare function getOrElse<A>(onNone: () => Task<A>): (as: TaskOption<A>) => Task<A>;
/**
* @since 0.1.0
*/
export declare const taskOption: Monad1<URI> & Alt1<URI>;
declare const alt: <A>(that: () => TaskOption<A>) => (fa: TaskOption<A>) => TaskOption<A>, ap: <A>(fa: TaskOption<A>) => <B>(fab: TaskOption<(a: A) => B>) => TaskOption<B>, apFirst: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<A>, apSecond: <B>(fb: TaskOption<B>) => <A>(fa: TaskOption<A>) => TaskOption<B>, chain: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<B>, chainFirst: <A, B>(f: (a: A) => TaskOption<B>) => (ma: TaskOption<A>) => TaskOption<A>, flatten: <A>(mma: TaskOption<TaskOption<A>>) => TaskOption<A>, map: <A, B>(f: (a: A) => B) => (fa: TaskOption<A>) => TaskOption<B>;
export { alt, ap, apFirst, apSecond, chain, chainFirst, flatten, map };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Option_1 = require("fp-ts/lib/Option");
var optionT = require("fp-ts/lib/OptionT");
var Task_1 = require("fp-ts/lib/Task");
var function_1 = require("fp-ts/lib/function");
var withTimeout_1 = require("./Task/withTimeout");
var OptionT_1 = require("fp-ts/lib/OptionT");
var pipeable_1 = require("fp-ts/lib/pipeable");
var T = OptionT_1.getOptionM(Task_1.task);
/**
* @since 0.1.0
*/
exports.URI = 'TaskOption';
var T = optionT.getOptionT2v(Task_1.task);
var foldT = optionT.fold(Task_1.task);
var TaskOption = /** @class */ (function () {
function TaskOption(value) {
this.value = value;
}
TaskOption.prototype.run = function () {
return this.value.run();
};
TaskOption.prototype.map = function (f) {
return new TaskOption(T.map(this.value, f));
};
TaskOption.prototype.ap = function (fab) {
return new TaskOption(T.ap(fab.value, this.value));
};
TaskOption.prototype.ap_ = function (fb) {
return fb.ap(this);
};
TaskOption.prototype.chain = function (f) {
return new TaskOption(T.chain(this.value, function (a) { return f(a).value; }));
};
TaskOption.prototype.fold = function (onNone, onSome) {
return foldT(onNone, onSome, this.value);
};
TaskOption.prototype.getOrElse = function (a) {
return this.fold(a, function_1.identity);
};
return TaskOption;
}());
exports.TaskOption = TaskOption;
var map = function (fa, f) { return fa.map(f); };
var of = function (a) { return new TaskOption(T.of(a)); };
var ap = function (fab, fa) { return fa.ap(fab); };
var chain = function (fa, f) { return fa.chain(f); };
exports.some = of;
exports.none = new TaskOption(Task_1.task.of(Option_1.none));
exports.fromOption = function (ma) { return new TaskOption(Task_1.task.of(ma)); };
exports.fromTask = function (ma) { return new TaskOption(ma.map(Option_1.some)); };
exports.tryCatch = function (f) {
return new TaskOption(Task_1.tryCatch(f, function () { return undefined; }).map(Option_1.fromEither));
};
/**
* Returns the `TaskOption` result if it completes within a timeout, or a fallback value instead.
*
* @example
* import { TaskOption, withTimeout } from 'fp-ts-contrib/lib/TaskOption'
* import { delay } from 'fp-ts/lib/Task'
* import { some, none } from 'fp-ts/lib/Option'
*
* const completeAfter2s = new TaskOption(delay(2000, some('result')))
*
* withTimeout(completeAfter2s, some('timeout'), 3000).run() // Promise(some('result'))
* withTimeout(completeAfter2s, none, 1000).run() // Promise(none)
* withTimeout(completeAfter2s, some('timeout'), 1000).run() // Promise(some('timeout'))
*
* @since 0.0.6
* @since 0.1.0
*/
exports.withTimeout = function (fa, onTimeout, millis) {
return new TaskOption(withTimeout_1.withTimeout(fa.value, onTimeout, millis));
};
exports.fromTask = T.fromM;
/**
* @since 0.1.0
*/
exports.fromOption = Task_1.of;
/**
* @since 0.1.0
*/
exports.none = T.none();
/**
* @since 0.1.0
*/
exports.some = T.of;
/**
* @since 0.1.0
*/
function fold(onNone, onSome) {
return function (as) { return T.fold(as, onNone, onSome); };
}
exports.fold = fold;
/**
* @since 0.1.0
*/
function getOrElse(onNone) {
return function (as) { return T.getOrElse(as, onNone); };
}
exports.getOrElse = getOrElse;
/**
* @since 0.1.0
*/
exports.taskOption = {
URI: exports.URI,
map: map,
of: of,
ap: ap,
chain: chain
map: T.map,
of: exports.some,
ap: T.ap,
chain: T.chain,
alt: T.alt
};
var _a = pipeable_1.pipeable(exports.taskOption), alt = _a.alt, ap = _a.ap, apFirst = _a.apFirst, apSecond = _a.apSecond, chain = _a.chain, chainFirst = _a.chainFirst, flatten = _a.flatten, map = _a.map;
exports.alt = alt;
exports.ap = ap;
exports.apFirst = apFirst;
exports.apSecond = apSecond;
exports.chain = chain;
exports.chainFirst = chainFirst;
exports.flatten = flatten;
exports.map = map;

@@ -1,3 +0,3 @@

import { HKT, Type, Type2, Type3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { MonadIO, MonadIO1, MonadIO2, MonadIO2C, MonadIO3, MonadIO3C } from 'fp-ts/lib/MonadIO';
import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT';
import { MonadIO, MonadIO1, MonadIO2, MonadIO2C, MonadIO3 } from 'fp-ts/lib/MonadIO';
/**

@@ -18,11 +18,10 @@ * Mimics the analogous Unix command: given an action `HKT<M, A>`, we can derive an action `HKT<M, [A, number]>` that

*
* timeIO(randomInt(30, 35).map(fib)).run() // [ 14930352, 127 ]
* timeIO(io.map(randomInt(30, 35), fib))() // [ 14930352, 127 ]
*
* @since 0.0.1
*/
export declare function time<M extends URIS3>(M: MonadIO3<M>): <U, L, A>(ma: Type3<M, U, L, A>) => Type3<M, U, L, [A, number]>;
export declare function time<M extends URIS3, U, L>(M: MonadIO3C<M, U, L>): <A>(ma: Type3<M, U, L, A>) => Type3<M, U, L, [A, number]>;
export declare function time<M extends URIS2>(M: MonadIO2<M>): <L, A>(ma: Type2<M, L, A>) => Type2<M, L, [A, number]>;
export declare function time<M extends URIS2, L>(M: MonadIO2C<M, L>): <A>(ma: Type2<M, L, A>) => Type2<M, L, [A, number]>;
export declare function time<M extends URIS>(M: MonadIO1<M>): <A>(ma: Type<M, A>) => Type<M, [A, number]>;
export declare function time<M extends URIS3>(M: MonadIO3<M>): <U, L, A>(ma: Kind3<M, U, L, A>) => Kind3<M, U, L, [A, number]>;
export declare function time<M extends URIS2>(M: MonadIO2<M>): <L, A>(ma: Kind2<M, L, A>) => Kind2<M, L, [A, number]>;
export declare function time<M extends URIS2, L>(M: MonadIO2C<M, L>): <A>(ma: Kind2<M, L, A>) => Kind2<M, L, [A, number]>;
export declare function time<M extends URIS>(M: MonadIO1<M>): <A>(ma: Kind<M, A>) => Kind<M, [A, number]>;
export declare function time<M>(M: MonadIO<M>): <A>(ma: HKT<M, A>) => HKT<M, [A, number]>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Date_1 = require("fp-ts/lib/Date");
var function_1 = require("fp-ts/lib/function");
function time(M) {
var nowM = M.fromIO(Date_1.now);
return function (ma) { return M.chain(nowM, function (start) { return M.chain(ma, function (a) { return M.map(nowM, function (end) { return function_1.tuple(a, end - start); }); }); }); };
return function (ma) { return M.chain(nowM, function (start) { return M.chain(ma, function (a) { return M.map(nowM, function (end) { return [a, end - start]; }); }); }); };
}
exports.time = time;
{
"name": "fp-ts-contrib",
"version": "0.0.6",
"version": "0.1.0",
"description": "A community driven utility package for fp-ts",

@@ -12,3 +12,3 @@ "files": [

"tsc": "tsc",
"lint": "tslint -p tsconfig.json src/**/*.ts test/**/*.ts",
"lint": "tslint -p tsconfig.tslint.json src/**/*.ts test/**/*.ts",
"jest": "jest",

@@ -35,3 +35,3 @@ "prettier": "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"",

"peerDependencies": {
"fp-ts": "^1.15.1"
"fp-ts": "^2.0.0-rc.6"
},

@@ -46,3 +46,3 @@ "devDependencies": {

"dtslint": "github:gcanti/dtslint",
"fp-ts": "^1.17.2",
"fp-ts": "^2.0.0-rc.7",
"jest": "^23.6.0",

@@ -56,3 +56,3 @@ "mocha": "^5.2.0",

"tslint-config-standard": "^8.0.1",
"typescript": "^3.3.3333"
"typescript": "^3.5.1"
},

@@ -59,0 +59,0 @@ "tags": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc