Skip to content
This repository has been archived by the owner on Apr 12, 2020. It is now read-only.

Commit

Permalink
Version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Jul 19, 2018
1 parent d077705 commit e33448e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2017 Aldwin Vlasblom
Copyright (c) 2018 Aldwin Vlasblom

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
57 changes: 28 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,52 @@

Turn non-concurrent [FantasyLand 3][FL3] Applicatives concurrent.

Most time-dependent applicatives are very useful as Monads, because it gives
them the ability to run sequentially, where each step depends on the previous.
However, they lose the ability to run concurrently. This library allows one to
wrap a [`Monad`][FL:Monad] (with sequential `ap`) in an
Most time-dependent applicatives are very useful as Monads, because it
gives them the ability to run sequentially, where each step depends on the
previous. However, they lose the ability to run concurrently. This library
allows one to wrap a [`Monad`][FL:Monad] (with sequential `ap`) in an
[`Alternative`][FL:Alternative] (with parallel `ap`).

## Usage

```js
//The concurrify function takes four arguments, explained below.
const concurrify = require('concurrify');
// The concurrify function takes four arguments, explained below.
const concurrify = require ('concurrify');

//We load the Type Representative of the Applicative we want to transform.
const Future = require('fluture');
// The Type Representative of the Applicative we want to transform.
const Future = require ('fluture');

//We create a "zero" instance and an "alt" function for "Alternative".
const zero = Future(() => {});
// A "zero" instance and an "alt" function for "Alternative".
const zero = Future (() => {});
const alt = Future.race;

//We create an override "ap" function that runs the Applicatives concurrently.
const ap = (mx, mf) => Future.both(mx, mf).map(([x, f]) => f(x));
// An override "ap" function that runs the Applicatives concurrently.
const ap = (mx, mf) => (Future.both (mx, mf)).map (([x, f]) => f (x));

//Calling concurrify with these arguments gives us a new Type Representative.
const ConcurrentFuture = concurrify(Future, zero, alt, ap);
// A new Type Representative created by concurrify.
const ConcurrentFuture = concurrify (Future, zero, alt, ap);

//We can use our type as such:
ConcurrentFuture(Future.of(1)).sequential.fork(console.error, console.log);
```

## API

```hs
concurrify :: (Applicative f, Alternative (m f))
=> (TypeRep f, f a, (f a, f a) -> f a, (f a, f (a -> b)) -> f b)
-> f c
-> m f c
// We can use our type as such:
const par = ConcurrentFuture (Future.of (1));
const seq = par.sequential;
seq.fork (console.error, console.log);
```

## Interoperability

* Implements [FantasyLand 3][FL3] `Alternative` (`of`, `zero`, `map`, `ap`, `alt`).
* Instances can be identified by, and are compared using, [Sanctuary Type Identifiers][STI].
* Implements [FantasyLand 3][FL3] `Alternative`
(`of`, `zero`, `map`, `ap`, `alt`).
* Instances can be identified by, and are compared using,
[Sanctuary Type Identifiers][STI].
* Instances can be converted to String representations according to
[Sanctuary Show][SS].

<!-- References -->
## API

#### <a name="concurrify" href="https://github.com/fluture-js/concurrify/blob/v1.1.0/index.js#L140">`concurrify :: (Applicative f, Alternative (m f)) => (TypeRep f, f a, (f a, f a) -⁠> f a, (f a, f (a -⁠> b)) -⁠> f b) -⁠> f c -⁠> m f c`</a>

[FL3]: https://github.com/fantasyland/fantasy-land/
[FL:Monad]: https://github.com/fantasyland/fantasy-land/#monad
[FL:Alternative]: https://github.com/fantasyland/fantasy-land/#alternative

[STI]: https://github.com/sanctuary-js/sanctuary-type-identifiers
[SS]: https://github.com/sanctuary-js/sanctuary-show
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "concurrify",
"version": "1.0.3",
"version": "1.1.0",
"description": "Turn non-concurrent FantasyLand Applicatives concurrent",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit e33448e

Please sign in to comment.