Comparing version 0.5.5 to 0.5.6
@@ -5,2 +5,14 @@ { | ||
{ | ||
"version": "0.5.6", | ||
"tag": "tempo-std_v0.5.6", | ||
"date": "Sun, 12 Jul 2020 03:32:19 GMT", | ||
"comments": { | ||
"patch": [ | ||
{ | ||
"comment": "Update implementation of AsyncResult." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.5.5", | ||
@@ -7,0 +19,0 @@ "tag": "tempo-std_v0.5.5", |
# Change Log - tempo-std | ||
This log was last generated on Mon, 08 Jun 2020 23:05:13 GMT and should not be manually modified. | ||
This log was last generated on Sun, 12 Jul 2020 03:32:19 GMT and should not be manually modified. | ||
## 0.5.6 | ||
Sun, 12 Jul 2020 03:32:19 GMT | ||
### Patches | ||
- Update implementation of AsyncResult. | ||
## 0.5.5 | ||
@@ -6,0 +13,0 @@ Mon, 08 Jun 2020 23:05:13 GMT |
import { Maybe } from './maybe'; | ||
import { Fun2, Fun3, Fun4, Fun5, Fun6 } from './types/functions'; | ||
import { Option } from './option'; | ||
import { Result, Success, Failure } from './result'; | ||
import { Async, Outcome, Loading, NotAsked } from './async'; | ||
export declare type AsyncResult<T, E, P = unknown> = Async<Result<T, E>, P>; | ||
export declare type Success<T> = { | ||
kind: 'Success'; | ||
value: T; | ||
}; | ||
export declare type Failure<E> = { | ||
kind: 'Failure'; | ||
error: E; | ||
}; | ||
export declare type NotAsked = { | ||
kind: 'NotAsked'; | ||
}; | ||
export declare type Loading<P> = { | ||
kind: 'Loading'; | ||
progress: P; | ||
}; | ||
export declare type AsyncResult<T, E, P = unknown> = Success<T> | Failure<E> | NotAsked | Loading<P>; | ||
export declare function success<T, E, P = unknown>(value: T): AsyncResult<T, E, P>; | ||
export declare function failure<T, E, P = unknown>(error: E): AsyncResult<T, E, P>; | ||
export declare const notAsked: Async<Result<never, never>, unknown>; | ||
export declare const notAsked: AsyncResult<never, never, unknown>; | ||
export declare function loading<T, E, P = unknown>(progress: P): AsyncResult<T, E, P>; | ||
export declare function forEach<A, Err>(result: AsyncResult<A, Err>, f: (a: A) => void): void; | ||
export declare function match<A, B, Err, Prog = unknown>(result: AsyncResult<A, Err, Prog>, f: (a: A) => B, fErr: (e: Err) => B, notAsked: B, fProg: (p: Prog) => B): B; | ||
export declare function map<A, B, Err, Prog>(async: AsyncResult<A, Err, Prog>, f: (a: A) => B): AsyncResult<B, Err, Prog>; | ||
export declare function map<A, B, Err, Prog>(result: AsyncResult<A, Err, Prog>, f: (a: A) => B): AsyncResult<B, Err, Prog>; | ||
export declare function mapN<A, B, C, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, f: Fun2<A, B, C>): AsyncResult<C, Err, Prog>; | ||
@@ -25,4 +38,4 @@ export declare function mapN<A, B, C, D, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, c: AsyncResult<C, Err, Prog>, f: Fun3<A, B, C, D>): AsyncResult<D, Err, Prog>; | ||
export declare function flatMapN<A, B, C, D, E, F, G, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, c: AsyncResult<C, Err, Prog>, d: AsyncResult<D, Err, Prog>, e: AsyncResult<E, Err, Prog>, g: AsyncResult<F, Err, Prog>, f: Fun6<A, B, C, D, E, F, AsyncResult<G, Err, Prog>>): AsyncResult<G, Err, Prog>; | ||
export declare function isSuccess<T, E, P>(async: AsyncResult<T, E, P>): async is Outcome<Success<T>>; | ||
export declare function isFailure<T, E, P>(async: AsyncResult<T, E, P>): async is Outcome<Failure<E>>; | ||
export declare function isSuccess<T, E, P>(async: AsyncResult<T, E, P>): async is Success<T>; | ||
export declare function isFailure<T, E, P>(async: AsyncResult<T, E, P>): async is Failure<E>; | ||
export declare function isLoading<T, E, P>(async: AsyncResult<T, E, P>): async is Loading<P>; | ||
@@ -36,5 +49,5 @@ export declare function isNotAsked<T, E, P>(async: AsyncResult<T, E, P>): async is NotAsked; | ||
export declare function toOption<T, P>(async: AsyncResult<T, P>): Option<T>; | ||
export declare function flatten<T, E, P>(async: AsyncResult<AsyncResult<T, E, P>, E, P>): AsyncResult<T, E, P>; | ||
export declare function cata<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNotOutcome: B): B; | ||
export declare function cataLazy<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNotOutcome: () => B): B; | ||
export declare function flatten<T, E, P>(result: AsyncResult<AsyncResult<T, E, P>, E, P>): AsyncResult<T, E, P>; | ||
export declare function cata<A, B, E, Prog>(result: AsyncResult<A, E, Prog>, f: (a: A) => B, ifNot: B): B; | ||
export declare function cataLazy<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNot: () => B): B; | ||
export declare function foldLeft<T, B, Prog>(async: AsyncResult<T, Prog>, f: (acc: B, curr: T) => B, b: B): B; | ||
@@ -45,4 +58,4 @@ export declare function all<T, P>(async: AsyncResult<T, P>, f: (v: T) => boolean): boolean; | ||
export declare function firstSuccess<A, Prog>(...args: AsyncResult<A, Prog>[]): AsyncResult<A, Prog>; | ||
export declare function recover<T, E, P>(async: AsyncResult<T, E, P>, whenNoOutcome: T): AsyncResult<T, E, P>; | ||
export declare function recover<T, E, P>(async: AsyncResult<T, E, P>, whenNoResult: T): AsyncResult<T, E, P>; | ||
export declare type T<V, E> = AsyncResult<V, E>; | ||
//# sourceMappingURL=async_result.d.ts.map |
@@ -13,19 +13,10 @@ /* | ||
*/ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
import { nothing } from './maybe'; | ||
import { nothing, just } from './maybe'; | ||
import { map as mapArray } from './arrays'; | ||
import { none } from './option'; | ||
import { success as successR, failure as failureR, map as mapR, mapN as mapNR, getOrElse as getOrElseR, getOrThrow as getOrThrowR, getOrElseLazy as getOrElseLazyR, toArray as toArrayR, cata as cataR, cataLazy as cataLazyR, toOption as toOptionR, toMaybe as toMaybeR, recover as recoverR, foldLeft as foldLeftR, any as anyR, each as eachR, all as allR, forEach as forEachR } from './result'; | ||
import { outcome, map as mapA, mapN as mapNA } from './async'; | ||
import { none, some } from './option'; | ||
export function success(value) { | ||
return outcome(successR(value)); | ||
return { kind: 'Success', value: value }; | ||
} | ||
export function failure(error) { | ||
return outcome(failureR(error)); | ||
return { kind: 'Failure', error: error }; | ||
} | ||
@@ -40,5 +31,6 @@ export var notAsked = { kind: 'NotAsked' }; | ||
case 'NotAsked': | ||
case 'Failure': | ||
return; | ||
case 'Outcome': | ||
forEachR(result.value, f); | ||
case 'Success': | ||
f(result.value); | ||
} | ||
@@ -48,13 +40,21 @@ } | ||
switch (result.kind) { | ||
case 'Loading': return fProg(result.progress); | ||
case 'NotAsked': return notAsked; | ||
case 'Outcome': | ||
switch (result.value.kind) { | ||
case 'Success': return f(result.value.value); | ||
case 'Failure': return fErr(result.value.error); | ||
} | ||
case 'Loading': | ||
return fProg(result.progress); | ||
case 'NotAsked': | ||
return notAsked; | ||
case 'Success': | ||
return f(result.value); | ||
case 'Failure': | ||
return fErr(result.error); | ||
} | ||
} | ||
export function map(async, f) { | ||
return mapA(async, function (r) { return mapR(r, f); }); | ||
export function map(result, f) { | ||
switch (result.kind) { | ||
case 'Loading': | ||
case 'NotAsked': | ||
case 'Failure': | ||
return result; | ||
case 'Success': | ||
return success(f(result.value)); | ||
} | ||
} | ||
@@ -67,9 +67,9 @@ export function mapN() { | ||
var f = args.pop(); | ||
return mapNA.apply(void 0, __spreadArrays([function () { | ||
var r = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
r[_i] = arguments[_i]; | ||
} | ||
return mapNR.apply(void 0, __spreadArrays([f], r)); | ||
}], args)); | ||
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { | ||
var a = args_1[_a]; | ||
if (a.kind === 'Failure' || a.kind === 'Loading' || a.kind === 'NotAsked') | ||
return a; | ||
} | ||
var results = mapArray(args, function (a) { return a.value; }); | ||
return success(f.apply(void 0, results)); | ||
} | ||
@@ -79,10 +79,8 @@ export function flatMap(async, f) { | ||
case 'NotAsked': | ||
case 'Loading': return async; | ||
case 'Outcome': | ||
switch (async.value.kind) { | ||
case 'Success': | ||
return f(async.value.value); | ||
case 'Failure': | ||
return failure(async.value.error); | ||
} | ||
case 'Loading': | ||
return async; | ||
case 'Success': | ||
return f(async.value); | ||
case 'Failure': | ||
return failure(async.error); | ||
} | ||
@@ -96,5 +94,5 @@ } | ||
var f = args.pop(); | ||
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { | ||
var a = args_1[_a]; | ||
if (a.kind === 'Loading' || a.kind === 'NotAsked') { | ||
for (var _a = 0, args_2 = args; _a < args_2.length; _a++) { | ||
var a = args_2[_a]; | ||
if (a.kind === 'Loading' || a.kind === 'NotAsked' || a.kind === 'Failure') { | ||
return a; | ||
@@ -107,6 +105,6 @@ } | ||
export function isSuccess(async) { | ||
return async.kind === 'Outcome' && async.value.kind === 'Success'; | ||
return async.kind === 'Success'; | ||
} | ||
export function isFailure(async) { | ||
return async.kind === 'Outcome' && async.value.kind === 'Failure'; | ||
return async.kind === 'Failure'; | ||
} | ||
@@ -121,5 +119,10 @@ export function isLoading(async) { | ||
switch (async.kind) { | ||
case 'NotAsked': throw 'Can\'t retrieve value from NotAsked'; | ||
case 'Loading': throw 'Can\'t retrieve value from Loading: ' + async.progress; | ||
case 'Outcome': return getOrThrowR(async.value); | ||
case 'NotAsked': | ||
throw "Can't retrieve value from NotAsked"; | ||
case 'Loading': | ||
throw "Can't retrieve value from Loading: " + async.progress; | ||
case 'Failure': | ||
throw "Can't retrieve value from Failure: " + async.error; | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -130,4 +133,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return alt; | ||
case 'Outcome': return getOrElseR(async.value, alt); | ||
case 'Loading': | ||
case 'Failure': | ||
return alt; | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -138,4 +144,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return alt(); | ||
case 'Outcome': return getOrElseLazyR(async.value, alt); | ||
case 'Loading': | ||
case 'Failure': | ||
return alt(); | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -146,4 +155,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return []; | ||
case 'Outcome': return toArrayR(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return []; | ||
case 'Success': | ||
return [async.value]; | ||
} | ||
@@ -154,4 +166,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return nothing; | ||
case 'Outcome': return toMaybeR(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return nothing; | ||
case 'Success': | ||
return just(async.value); | ||
} | ||
@@ -162,31 +177,39 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return none; | ||
case 'Outcome': return toOptionR(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return none; | ||
case 'Success': | ||
return some(async.value); | ||
} | ||
} | ||
export function flatten(async) { | ||
switch (async.kind) { | ||
case 'NotAsked': return notAsked; | ||
case 'Loading': return loading(async.progress); | ||
case 'Outcome': | ||
if (async.value.kind === 'Success' && async.value.value.kind === 'Outcome' && async.value.value.value.kind === 'Success') { | ||
return async.value.value; | ||
} | ||
else { | ||
return async; | ||
} | ||
export function flatten(result) { | ||
switch (result.kind) { | ||
case 'NotAsked': | ||
return notAsked; | ||
case 'Loading': | ||
return loading(result.progress); | ||
case 'Failure': | ||
return failure(result.error); | ||
case 'Success': | ||
return result.value; | ||
} | ||
} | ||
export function cata(async, f, ifNotOutcome) { | ||
switch (async.kind) { | ||
export function cata(result, f, ifNot) { | ||
switch (result.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return ifNotOutcome; | ||
case 'Outcome': return cataR(async.value, f, ifNotOutcome); | ||
case 'Loading': | ||
case 'Failure': | ||
return ifNot; | ||
case 'Success': | ||
return f(result.value); | ||
} | ||
} | ||
export function cataLazy(async, f, ifNotOutcome) { | ||
export function cataLazy(async, f, ifNot) { | ||
switch (async.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return ifNotOutcome(); | ||
case 'Outcome': return cataLazyR(async.value, f, ifNotOutcome); | ||
case 'Loading': | ||
case 'Failure': | ||
return ifNot(); | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -197,4 +220,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return b; | ||
case 'Outcome': return foldLeftR(async.value, f, b); | ||
case 'Loading': | ||
case 'Failure': | ||
return b; | ||
case 'Success': | ||
return f(b, async.value); | ||
} | ||
@@ -205,4 +231,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return true; | ||
case 'Outcome': return allR(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return true; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -213,4 +242,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return false; | ||
case 'Outcome': return anyR(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return false; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -221,4 +253,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return; | ||
case 'Outcome': return eachR(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -231,9 +266,9 @@ } | ||
} | ||
for (var _a = 0, args_2 = args; _a < args_2.length; _a++) { | ||
var a = args_2[_a]; | ||
for (var _a = 0, args_3 = args; _a < args_3.length; _a++) { | ||
var a = args_3[_a]; | ||
if (isSuccess(a)) | ||
return a; | ||
} | ||
for (var _b = 0, args_3 = args; _b < args_3.length; _b++) { | ||
var a = args_3[_b]; | ||
for (var _b = 0, args_4 = args; _b < args_4.length; _b++) { | ||
var a = args_4[_b]; | ||
return a; | ||
@@ -243,9 +278,12 @@ } | ||
} | ||
export function recover(async, whenNoOutcome) { | ||
export function recover(async, whenNoResult) { | ||
switch (async.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return success(whenNoOutcome); | ||
case 'Outcome': return outcome(recoverR(async.value, whenNoOutcome)); | ||
case 'Loading': | ||
case 'Failure': | ||
return success(whenNoResult); | ||
case 'Success': | ||
return success(async.value); | ||
} | ||
} | ||
//# sourceMappingURL=async_result.js.map |
import { Maybe } from './maybe'; | ||
import { Fun2, Fun3, Fun4, Fun5, Fun6 } from './types/functions'; | ||
import { Option } from './option'; | ||
import { Result, Success, Failure } from './result'; | ||
import { Async, Outcome, Loading, NotAsked } from './async'; | ||
export declare type AsyncResult<T, E, P = unknown> = Async<Result<T, E>, P>; | ||
export declare type Success<T> = { | ||
kind: 'Success'; | ||
value: T; | ||
}; | ||
export declare type Failure<E> = { | ||
kind: 'Failure'; | ||
error: E; | ||
}; | ||
export declare type NotAsked = { | ||
kind: 'NotAsked'; | ||
}; | ||
export declare type Loading<P> = { | ||
kind: 'Loading'; | ||
progress: P; | ||
}; | ||
export declare type AsyncResult<T, E, P = unknown> = Success<T> | Failure<E> | NotAsked | Loading<P>; | ||
export declare function success<T, E, P = unknown>(value: T): AsyncResult<T, E, P>; | ||
export declare function failure<T, E, P = unknown>(error: E): AsyncResult<T, E, P>; | ||
export declare const notAsked: Async<Result<never, never>, unknown>; | ||
export declare const notAsked: AsyncResult<never, never, unknown>; | ||
export declare function loading<T, E, P = unknown>(progress: P): AsyncResult<T, E, P>; | ||
export declare function forEach<A, Err>(result: AsyncResult<A, Err>, f: (a: A) => void): void; | ||
export declare function match<A, B, Err, Prog = unknown>(result: AsyncResult<A, Err, Prog>, f: (a: A) => B, fErr: (e: Err) => B, notAsked: B, fProg: (p: Prog) => B): B; | ||
export declare function map<A, B, Err, Prog>(async: AsyncResult<A, Err, Prog>, f: (a: A) => B): AsyncResult<B, Err, Prog>; | ||
export declare function map<A, B, Err, Prog>(result: AsyncResult<A, Err, Prog>, f: (a: A) => B): AsyncResult<B, Err, Prog>; | ||
export declare function mapN<A, B, C, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, f: Fun2<A, B, C>): AsyncResult<C, Err, Prog>; | ||
@@ -25,4 +38,4 @@ export declare function mapN<A, B, C, D, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, c: AsyncResult<C, Err, Prog>, f: Fun3<A, B, C, D>): AsyncResult<D, Err, Prog>; | ||
export declare function flatMapN<A, B, C, D, E, F, G, Err, Prog>(a: AsyncResult<A, Err, Prog>, b: AsyncResult<B, Err, Prog>, c: AsyncResult<C, Err, Prog>, d: AsyncResult<D, Err, Prog>, e: AsyncResult<E, Err, Prog>, g: AsyncResult<F, Err, Prog>, f: Fun6<A, B, C, D, E, F, AsyncResult<G, Err, Prog>>): AsyncResult<G, Err, Prog>; | ||
export declare function isSuccess<T, E, P>(async: AsyncResult<T, E, P>): async is Outcome<Success<T>>; | ||
export declare function isFailure<T, E, P>(async: AsyncResult<T, E, P>): async is Outcome<Failure<E>>; | ||
export declare function isSuccess<T, E, P>(async: AsyncResult<T, E, P>): async is Success<T>; | ||
export declare function isFailure<T, E, P>(async: AsyncResult<T, E, P>): async is Failure<E>; | ||
export declare function isLoading<T, E, P>(async: AsyncResult<T, E, P>): async is Loading<P>; | ||
@@ -36,5 +49,5 @@ export declare function isNotAsked<T, E, P>(async: AsyncResult<T, E, P>): async is NotAsked; | ||
export declare function toOption<T, P>(async: AsyncResult<T, P>): Option<T>; | ||
export declare function flatten<T, E, P>(async: AsyncResult<AsyncResult<T, E, P>, E, P>): AsyncResult<T, E, P>; | ||
export declare function cata<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNotOutcome: B): B; | ||
export declare function cataLazy<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNotOutcome: () => B): B; | ||
export declare function flatten<T, E, P>(result: AsyncResult<AsyncResult<T, E, P>, E, P>): AsyncResult<T, E, P>; | ||
export declare function cata<A, B, E, Prog>(result: AsyncResult<A, E, Prog>, f: (a: A) => B, ifNot: B): B; | ||
export declare function cataLazy<A, B, Prog>(async: AsyncResult<A, Prog>, f: (a: A) => B, ifNot: () => B): B; | ||
export declare function foldLeft<T, B, Prog>(async: AsyncResult<T, Prog>, f: (acc: B, curr: T) => B, b: B): B; | ||
@@ -45,4 +58,4 @@ export declare function all<T, P>(async: AsyncResult<T, P>, f: (v: T) => boolean): boolean; | ||
export declare function firstSuccess<A, Prog>(...args: AsyncResult<A, Prog>[]): AsyncResult<A, Prog>; | ||
export declare function recover<T, E, P>(async: AsyncResult<T, E, P>, whenNoOutcome: T): AsyncResult<T, E, P>; | ||
export declare function recover<T, E, P>(async: AsyncResult<T, E, P>, whenNoResult: T): AsyncResult<T, E, P>; | ||
export declare type T<V, E> = AsyncResult<V, E>; | ||
//# sourceMappingURL=async_result.d.ts.map |
@@ -14,9 +14,2 @@ "use strict"; | ||
*/ | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -27,10 +20,8 @@ exports.recover = exports.firstSuccess = exports.each = exports.any = exports.all = exports.foldLeft = exports.cataLazy = exports.cata = exports.flatten = exports.toOption = exports.toMaybe = exports.toArray = exports.getOrElseLazy = exports.getOrElse = exports.getOrThrow = exports.isNotAsked = exports.isLoading = exports.isFailure = exports.isSuccess = exports.flatMapN = exports.flatMap = exports.mapN = exports.map = exports.match = exports.forEach = exports.loading = exports.notAsked = exports.failure = exports.success = void 0; | ||
var option_1 = require("./option"); | ||
var result_1 = require("./result"); | ||
var async_1 = require("./async"); | ||
function success(value) { | ||
return async_1.outcome(result_1.success(value)); | ||
return { kind: 'Success', value: value }; | ||
} | ||
exports.success = success; | ||
function failure(error) { | ||
return async_1.outcome(result_1.failure(error)); | ||
return { kind: 'Failure', error: error }; | ||
} | ||
@@ -47,5 +38,6 @@ exports.failure = failure; | ||
case 'NotAsked': | ||
case 'Failure': | ||
return; | ||
case 'Outcome': | ||
result_1.forEach(result.value, f); | ||
case 'Success': | ||
f(result.value); | ||
} | ||
@@ -56,14 +48,22 @@ } | ||
switch (result.kind) { | ||
case 'Loading': return fProg(result.progress); | ||
case 'NotAsked': return notAsked; | ||
case 'Outcome': | ||
switch (result.value.kind) { | ||
case 'Success': return f(result.value.value); | ||
case 'Failure': return fErr(result.value.error); | ||
} | ||
case 'Loading': | ||
return fProg(result.progress); | ||
case 'NotAsked': | ||
return notAsked; | ||
case 'Success': | ||
return f(result.value); | ||
case 'Failure': | ||
return fErr(result.error); | ||
} | ||
} | ||
exports.match = match; | ||
function map(async, f) { | ||
return async_1.map(async, function (r) { return result_1.map(r, f); }); | ||
function map(result, f) { | ||
switch (result.kind) { | ||
case 'Loading': | ||
case 'NotAsked': | ||
case 'Failure': | ||
return result; | ||
case 'Success': | ||
return success(f(result.value)); | ||
} | ||
} | ||
@@ -77,9 +77,9 @@ exports.map = map; | ||
var f = args.pop(); | ||
return async_1.mapN.apply(void 0, __spreadArrays([function () { | ||
var r = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
r[_i] = arguments[_i]; | ||
} | ||
return result_1.mapN.apply(void 0, __spreadArrays([f], r)); | ||
}], args)); | ||
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { | ||
var a = args_1[_a]; | ||
if (a.kind === 'Failure' || a.kind === 'Loading' || a.kind === 'NotAsked') | ||
return a; | ||
} | ||
var results = arrays_1.map(args, function (a) { return a.value; }); | ||
return success(f.apply(void 0, results)); | ||
} | ||
@@ -90,10 +90,8 @@ exports.mapN = mapN; | ||
case 'NotAsked': | ||
case 'Loading': return async; | ||
case 'Outcome': | ||
switch (async.value.kind) { | ||
case 'Success': | ||
return f(async.value.value); | ||
case 'Failure': | ||
return failure(async.value.error); | ||
} | ||
case 'Loading': | ||
return async; | ||
case 'Success': | ||
return f(async.value); | ||
case 'Failure': | ||
return failure(async.error); | ||
} | ||
@@ -108,5 +106,5 @@ } | ||
var f = args.pop(); | ||
for (var _a = 0, args_1 = args; _a < args_1.length; _a++) { | ||
var a = args_1[_a]; | ||
if (a.kind === 'Loading' || a.kind === 'NotAsked') { | ||
for (var _a = 0, args_2 = args; _a < args_2.length; _a++) { | ||
var a = args_2[_a]; | ||
if (a.kind === 'Loading' || a.kind === 'NotAsked' || a.kind === 'Failure') { | ||
return a; | ||
@@ -120,7 +118,7 @@ } | ||
function isSuccess(async) { | ||
return async.kind === 'Outcome' && async.value.kind === 'Success'; | ||
return async.kind === 'Success'; | ||
} | ||
exports.isSuccess = isSuccess; | ||
function isFailure(async) { | ||
return async.kind === 'Outcome' && async.value.kind === 'Failure'; | ||
return async.kind === 'Failure'; | ||
} | ||
@@ -138,5 +136,10 @@ exports.isFailure = isFailure; | ||
switch (async.kind) { | ||
case 'NotAsked': throw 'Can\'t retrieve value from NotAsked'; | ||
case 'Loading': throw 'Can\'t retrieve value from Loading: ' + async.progress; | ||
case 'Outcome': return result_1.getOrThrow(async.value); | ||
case 'NotAsked': | ||
throw "Can't retrieve value from NotAsked"; | ||
case 'Loading': | ||
throw "Can't retrieve value from Loading: " + async.progress; | ||
case 'Failure': | ||
throw "Can't retrieve value from Failure: " + async.error; | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -148,4 +151,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return alt; | ||
case 'Outcome': return result_1.getOrElse(async.value, alt); | ||
case 'Loading': | ||
case 'Failure': | ||
return alt; | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -157,4 +163,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return alt(); | ||
case 'Outcome': return result_1.getOrElseLazy(async.value, alt); | ||
case 'Loading': | ||
case 'Failure': | ||
return alt(); | ||
case 'Success': | ||
return async.value; | ||
} | ||
@@ -166,4 +175,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return []; | ||
case 'Outcome': return result_1.toArray(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return []; | ||
case 'Success': | ||
return [async.value]; | ||
} | ||
@@ -175,4 +187,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return maybe_1.nothing; | ||
case 'Outcome': return result_1.toMaybe(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return maybe_1.nothing; | ||
case 'Success': | ||
return maybe_1.just(async.value); | ||
} | ||
@@ -184,34 +199,42 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return option_1.none; | ||
case 'Outcome': return result_1.toOption(async.value); | ||
case 'Loading': | ||
case 'Failure': | ||
return option_1.none; | ||
case 'Success': | ||
return option_1.some(async.value); | ||
} | ||
} | ||
exports.toOption = toOption; | ||
function flatten(async) { | ||
switch (async.kind) { | ||
case 'NotAsked': return exports.notAsked; | ||
case 'Loading': return loading(async.progress); | ||
case 'Outcome': | ||
if (async.value.kind === 'Success' && async.value.value.kind === 'Outcome' && async.value.value.value.kind === 'Success') { | ||
return async.value.value; | ||
} | ||
else { | ||
return async; | ||
} | ||
function flatten(result) { | ||
switch (result.kind) { | ||
case 'NotAsked': | ||
return exports.notAsked; | ||
case 'Loading': | ||
return loading(result.progress); | ||
case 'Failure': | ||
return failure(result.error); | ||
case 'Success': | ||
return result.value; | ||
} | ||
} | ||
exports.flatten = flatten; | ||
function cata(async, f, ifNotOutcome) { | ||
switch (async.kind) { | ||
function cata(result, f, ifNot) { | ||
switch (result.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return ifNotOutcome; | ||
case 'Outcome': return result_1.cata(async.value, f, ifNotOutcome); | ||
case 'Loading': | ||
case 'Failure': | ||
return ifNot; | ||
case 'Success': | ||
return f(result.value); | ||
} | ||
} | ||
exports.cata = cata; | ||
function cataLazy(async, f, ifNotOutcome) { | ||
function cataLazy(async, f, ifNot) { | ||
switch (async.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return ifNotOutcome(); | ||
case 'Outcome': return result_1.cataLazy(async.value, f, ifNotOutcome); | ||
case 'Loading': | ||
case 'Failure': | ||
return ifNot(); | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -223,4 +246,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return b; | ||
case 'Outcome': return result_1.foldLeft(async.value, f, b); | ||
case 'Loading': | ||
case 'Failure': | ||
return b; | ||
case 'Success': | ||
return f(b, async.value); | ||
} | ||
@@ -232,4 +258,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return true; | ||
case 'Outcome': return result_1.all(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return true; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -241,4 +270,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return false; | ||
case 'Outcome': return result_1.any(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return false; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -250,4 +282,7 @@ } | ||
case 'NotAsked': | ||
case 'Loading': return; | ||
case 'Outcome': return result_1.each(async.value, f); | ||
case 'Loading': | ||
case 'Failure': | ||
return; | ||
case 'Success': | ||
return f(async.value); | ||
} | ||
@@ -261,9 +296,9 @@ } | ||
} | ||
for (var _a = 0, args_2 = args; _a < args_2.length; _a++) { | ||
var a = args_2[_a]; | ||
for (var _a = 0, args_3 = args; _a < args_3.length; _a++) { | ||
var a = args_3[_a]; | ||
if (isSuccess(a)) | ||
return a; | ||
} | ||
for (var _b = 0, args_3 = args; _b < args_3.length; _b++) { | ||
var a = args_3[_b]; | ||
for (var _b = 0, args_4 = args; _b < args_4.length; _b++) { | ||
var a = args_4[_b]; | ||
return a; | ||
@@ -274,7 +309,10 @@ } | ||
exports.firstSuccess = firstSuccess; | ||
function recover(async, whenNoOutcome) { | ||
function recover(async, whenNoResult) { | ||
switch (async.kind) { | ||
case 'NotAsked': | ||
case 'Loading': return success(whenNoOutcome); | ||
case 'Outcome': return async_1.outcome(result_1.recover(async.value, whenNoOutcome)); | ||
case 'Loading': | ||
case 'Failure': | ||
return success(whenNoResult); | ||
case 'Success': | ||
return success(async.value); | ||
} | ||
@@ -281,0 +319,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"description": "Std library for TypeScript. Natural complement to the tempo libs.", | ||
"version": "0.5.5", | ||
"version": "0.5.6", | ||
"keywords": [ | ||
@@ -9,0 +9,0 @@ "tempo", |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8886
712316