Comparing version
declare module 'fluture' { | ||
interface RejectFunction<L> { | ||
export interface RejectFunction<L> { | ||
(error: L): void | ||
} | ||
interface ResolveFunction<R> { | ||
export interface ResolveFunction<R> { | ||
(value: R): void | ||
} | ||
interface Cancel { | ||
export interface Cancel { | ||
(): void | ||
} | ||
interface Nodeback<E, R> { | ||
export interface Nodeback<E, R> { | ||
(err: E | null, value?: R): void | ||
} | ||
interface Next<T> { | ||
export interface Next<T> { | ||
done: false | ||
@@ -24,3 +24,3 @@ value: T | ||
interface Done<T> { | ||
export interface Done<T> { | ||
done: true | ||
@@ -30,7 +30,7 @@ value: T | ||
interface Iterator<N, D> { | ||
export interface Iterator<N, D> { | ||
next(value?: N): Next<N> | Done<D> | ||
} | ||
interface Generator<Y, R> { | ||
export interface Generator<Y, R> { | ||
(): Iterator<Y, R> | ||
@@ -40,3 +40,3 @@ } | ||
/** The function is waiting for two more arguments. */ | ||
interface AwaitingTwo<A, B, R> { | ||
export interface AwaitingTwo<A, B, R> { | ||
(a: A, b: B): R | ||
@@ -47,3 +47,3 @@ (a: A): (b: B) => R | ||
/** The function is waiting for three more arguments. */ | ||
interface AwaitingThree<A, B, C, R> { | ||
export interface AwaitingThree<A, B, C, R> { | ||
(a: A, b: B, c: C): R | ||
@@ -133,2 +133,6 @@ (a: A, b: B): (c: C) => R | ||
/** Race two ConcurrentFutures. See https://github.com/fluture-js/Fluture#alt */ | ||
export function alt<L, R>(left: ConcurrentFuture<L, R>, right: ConcurrentFuture<L, R>): ConcurrentFuture<L, R> | ||
export function alt<L, R>(left: ConcurrentFuture<L, R>): (right: ConcurrentFuture<L, R>) => ConcurrentFuture<L, R> | ||
/** Apply the function in the left Future to the value in the right Future. See https://github.com/fluture-js/Fluture#ap */ | ||
@@ -138,2 +142,6 @@ export function ap<L, RA, RB>(apply: Future<L, (value: RA) => RB>, value: Future<L, RA>): Future<L, RB> | ||
/** Apply the function in the left ConcurrentFuture to the value in the right ConcurrentFuture. See https://github.com/fluture-js/Fluture#ap */ | ||
export function ap<L, RA, RB>(apply: ConcurrentFuture<L, (value: RA) => RB>, value: ConcurrentFuture<L, RA>): ConcurrentFuture<L, RB> | ||
export function ap<L, RA, RB>(apply: ConcurrentFuture<L, (value: RA) => RB>): (value: ConcurrentFuture<L, RA>) => ConcurrentFuture<L, RB> | ||
/** Create a Future which resolves with the return value of the given function, or rejects with the error it throws. See https://github.com/fluture-js/Fluture#try */ | ||
@@ -250,2 +258,6 @@ export function attempt<L, R>(fn: () => R): Future<L, R> | ||
/** Map over the resolution value of the given ConcurrentFuture. See https://github.com/fluture-js/Fluture#map */ | ||
export function map<L, RA, RB>(mapper: (value: RA) => RB, source: ConcurrentFuture<L, RA>): ConcurrentFuture<L, RB> | ||
export function map<L, RA, RB>(mapper: (value: RA) => RB): (source: ConcurrentFuture<L, RA>) => ConcurrentFuture<L, RB> | ||
/** Map over the rejection reason of the given Future. See https://github.com/fluture-js/Fluture#maprej */ | ||
@@ -330,5 +342,20 @@ export function mapRej<LA, LB, R>(mapper: (reason: LA) => LB, source: Future<LA, R>): Future<LB, R> | ||
/** Create a ConcurrentFuture using a Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ | ||
export function Par<L, R>(source: Future<L, R>): ConcurrentFuture<L, R> | ||
export interface Par { | ||
/** Create a ConcurrentFuture using a Future. See https://github.com/fluture-js/Fluture#concurrentfuture */ | ||
<L, R>(source: Future<L, R>): ConcurrentFuture<L, R> | ||
of<R>(value: R): ConcurrentFuture<never, R> | ||
zero(): ConcurrentFuture<never, never> | ||
ap: typeof ap | ||
map: typeof map | ||
alt: typeof alt | ||
'@@type': string | ||
} | ||
export const Par: Par | ||
} |
{ | ||
"name": "fluture", | ||
"version": "7.0.1", | ||
"version": "7.1.0", | ||
"description": "FantasyLand compliant (monadic) alternative to Promises", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
109
README.md
@@ -86,4 +86,6 @@ # [](#butterfly) | ||
All versions of Fantasy Land are supported. | ||
* `Future.Par` implements [Fantasy Land 3][FL] `Alternative` (`of`, `zero`, `map`, `ap`, `alt`). | ||
* The Future representative contains a `@@type` property for [Sanctuary Type Identifiers][STI]. | ||
* `Future.Par` implements [Fantasy Land 3][FL] and [Static Land][6] -compatible | ||
`Alternative` (`of`, `zero`, `map`, `ap`, `alt`). | ||
* The Future and ConcurrentFuture representatives contain `@@type` properties | ||
for [Sanctuary Type Identifiers][STI]. | ||
@@ -266,2 +268,4 @@ ## Butterfly | ||
[Fantasy Land Apply specification][FL:apply]. | ||
- [**Alt**][Z:Alt] - Values which conform to the | ||
[Fantasy Land Alt specification][FL:alt]. | ||
@@ -705,2 +709,3 @@ ### Stack safety | ||
Future.map :: Functor m => (a -> b) -> m a -> m b | ||
Par.map :: Functor m => (a -> b) -> m a -> m b | ||
Future.prototype.map :: Future e a ~> (a -> b) -> Future e b | ||
@@ -881,2 +886,3 @@ ``` | ||
Future.ap :: Apply m => m (a -> b) -> m a -> m b | ||
Par.ap :: Apply m => m (a -> b) -> m a -> m b | ||
Future.prototype.ap :: Future e (a -> b) ~> Future e a -> Future e b | ||
@@ -1190,14 +1196,5 @@ ``` | ||
<details><summary><code>Par :: Future a b -> ConcurrentFuture a b</code></summary> | ||
```hs | ||
Par :: Future a b -> ConcurrentFuture a b | ||
seq :: ConcurrentFuture a b -> Future a b | ||
``` | ||
</details> | ||
ConcurrentFuture (or `Par` for short) is the result of applying | ||
[`concurrify`][concurrify] to `Future`. It provides a mechanism for constructing | ||
a [Fantasy Land `Alternative`][FL:alternative] from a member of `Future`. This | ||
The `ConcurrentFuture` type is the result of applying [`concurrify`][concurrify] | ||
to `Future`. It provides a mechanism for constructing a | ||
[Fantasy Land `Alternative`][FL:alternative] from a member of `Future`. This | ||
allows Futures to benefit from the Alternative Interface, which includes | ||
@@ -1207,8 +1204,9 @@ parallel `ap`, `zero` and `alt`. | ||
The idea is that you can switch back and forth between `Future` and | ||
`ConcurrentFuture`, using `Par` and `seq`, to get sequential or concurrent | ||
behaviour respectively. It's useful if you want a purely algebraic alternative | ||
to [`parallel`](#parallel) and [`race`](#race). | ||
`ConcurrentFuture`, using [`Par`](#par) and [`seq`](#seq), to get sequential or | ||
concurrent behaviour respectively. It's a useful type to pass to abstractions | ||
that don't know about Future-specific functions like [`parallel`](#parallel) or | ||
[`race`](#race), but *do* know how to operate on Apply and Alternative. | ||
```js | ||
const {of, ap, zero, alt, sequence} = require('sanctuary'); | ||
const {of, ap, sequence} = require('sanctuary'); | ||
const {Future, Par, seq} = require('fluture'); | ||
@@ -1231,6 +1229,75 @@ | ||
//> [x, f] | ||
``` | ||
//Or racing with alternative | ||
seq(alt(zero(Par), parx)).value(console.log); | ||
##### Par | ||
Converts a Future to a ConcurrentFuture. | ||
<details><summary><code>Par :: Future a b -> ConcurrentFuture a b</code></summary> | ||
```hs | ||
Par :: Future a b -> ConcurrentFuture a b | ||
``` | ||
</details> | ||
##### Par.of | ||
Constructs a ConcurrentFuture with the given resolution value. | ||
<details><summary><code>Par.of :: b -> ConcurrentFuture a b</code></summary> | ||
```hs | ||
Par.of :: b -> ConcurrentFuture a b | ||
``` | ||
</details> | ||
##### Par.zero | ||
Constructs a ConcurrentFuture which will never resolve or reject with anything. | ||
<details><summary><code>Par.zero :: () -> ConcurrentFuture a a</code></summary> | ||
```hs | ||
Par.zero :: () -> ConcurrentFuture a a | ||
``` | ||
</details> | ||
##### seq | ||
Converts a ConcurrentFuture to a Future. | ||
<details><summary><code>seq :: ConcurrentFuture a b -> Future a b</code></summary> | ||
```hs | ||
seq :: ConcurrentFuture a b -> Future a b | ||
``` | ||
</details> | ||
##### alt | ||
Select one of two [Alts](#types). In terms of the `ConcurrentFuture` | ||
type, this means racing the two against one another with the same | ||
semantics as [`race`](#race). | ||
<details><summary><code>alt :: Alt f => f a -> f a -> f a</code></summary> | ||
```hs | ||
alt :: Alt f => f a -> f a -> f a | ||
Par.alt :: Alt f => f a -> f a -> f a | ||
``` | ||
</details> | ||
```js | ||
import {Future, Par, seq, alt} from 'fluture'; | ||
seq(alt(Par.zero, Par.of(1))).value(console.log); | ||
//> 1 | ||
seq(alt(Par(Future.after(20, 1)), Future.after(10, 2))).value(console.log); | ||
//> 2 | ||
``` | ||
@@ -1476,2 +1543,3 @@ | ||
[FL]: https://github.com/fantasyland/fantasy-land | ||
[FL:alt]: https://github.com/fantasyland/fantasy-land#alt | ||
[FL:alternative]: https://github.com/fantasyland/fantasy-land#alternative | ||
@@ -1502,2 +1570,3 @@ [FL:functor]: https://github.com/fantasyland/fantasy-land#functor | ||
[Z:Apply]: https://github.com/sanctuary-js/sanctuary-type-classes#Apply | ||
[Z:Alt]: https://github.com/sanctuary-js/sanctuary-type-classes#Alt | ||
@@ -1504,0 +1573,0 @@ [$]: https://github.com/sanctuary-js/sanctuary-def |
export {ap} from './dispatchers/ap'; | ||
export {alt} from './dispatchers/alt'; | ||
export {map} from './dispatchers/map'; | ||
@@ -3,0 +4,0 @@ export {bimap} from './dispatchers/bimap'; |
@@ -7,3 +7,4 @@ export const FL = { | ||
ap: 'fantasy-land/ap', | ||
of: 'fantasy-land/of' | ||
of: 'fantasy-land/of', | ||
zero: 'fantasy-land/zero' | ||
}; | ||
@@ -10,0 +11,0 @@ |
import concurrify from 'concurrify'; | ||
import type from 'sanctuary-type-identifiers'; | ||
import {Core, Future, never} from './core'; | ||
import {race} from './dispatchers'; | ||
import {race, ap, map, alt} from './dispatchers'; | ||
import {noop, show} from './internal/fn'; | ||
import {isFunction} from './internal/is'; | ||
import {typeError, invalidArgument} from './internal/throw'; | ||
import {FL} from './internal/const'; | ||
@@ -59,2 +60,8 @@ function check$ap$f(f){ | ||
Par.of = Par[FL.of]; | ||
Par.zero = Par[FL.zero]; | ||
Par.map = map; | ||
Par.ap = ap; | ||
Par.alt = alt; | ||
export function isParallel(x){ | ||
@@ -61,0 +68,0 @@ return x instanceof Par || type(x) === Par['@@type']; |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
206483
2.08%59
1.72%3931
1.39%1581
4.56%