Skip to content
This repository has been archived by the owner on Sep 9, 2023. It is now read-only.

Commit

Permalink
a bit more progress on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuminecz committed Dec 20, 2016
1 parent cd7df6e commit e185060
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 102 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[ignore]
.*/node_modules/conventional-changelog-core/test/
.*/node_modules/nyc/
.*/node_modules/radium/
.*/lib

[include]
Expand Down
109 changes: 25 additions & 84 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,6 @@ <h3 class='mb0 no-anchor'>phantasy</h3>
<ul class='list-reset py1-ul pl1'>
<li class='h5'><span>Instance members</span></li>

<li><a
href='#Identity#constructor'
class='regular pre-open'>
#constructor
</a></li>

<li><a
href='#Identity#map'
class='regular pre-open'>
Expand Down Expand Up @@ -1025,7 +1019,7 @@ <h3 class='fl m0' id='eff'>


<p>The <code>Eff</code> monad</p>
<p>Represents synchronous computations which are both dependency-injected and explicitly effectful</p>
<p>Represents a synchronous computation which is both dependency-injected and explicitly effectful</p>


<div class='pre p1 fill-light mt0'>new Eff()</div>
Expand Down Expand Up @@ -1490,6 +1484,7 @@ <h3 class='fl m0' id='effresult'>


<p>The <code>EffResult</code> monad</p>
<p>Represents a synchronous computation that can succeed or fail, and is both dependency-injected and explicitly effectul</p>


<div class='pre p1 fill-light mt0'>new EffResult()</div>
Expand Down Expand Up @@ -1956,7 +1951,7 @@ <h3 class='fl m0' id='effresult'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>map(f)</span>
<span class='code strong strong truncate'>map(transform)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
Expand All @@ -1965,9 +1960,11 @@ <h3 class='fl m0' id='effresult'>


<p><code>map :: EffResult e a x ~> (a -> b) -> EffResult e b x</code></p>
<p>Transform the result of the <code>EffResult</code> if successful,
otherwise the original <code>EffResult</code> is returned</p>


<div class='pre p1 fill-light mt0'>map(f: function (a: A): B): <a href="#effresult">EffResult</a>&#x3C;E, B, X></div>
<div class='pre p1 fill-light mt0'>map(transform: function (a: A): B): <a href="#effresult">EffResult</a>&#x3C;E, B, X></div>



Expand All @@ -1983,7 +1980,7 @@ <h3 class='fl m0' id='effresult'>

<div class='space-bottom0'>
<div>
<span class='code bold'>f</span> <code class='quiet'>(function (a: A): B)</code>
<span class='code bold'>transform</span> <code class='quiet'>(function (a: A): B)</code>

</div>

Expand Down Expand Up @@ -2028,6 +2025,8 @@ <h3 class='fl m0' id='effresult'>


<p><code>andThen :: EffResult e a x ~> (a -> EffResult f b x) -> EffResult (e &#x26; f) b x</code></p>
<p>Chains the result of the <code>EffResult</code> to another <code>EffResult</code>-producing
function if successful, otherwise the original <code>EffResult</code> is returned.</p>


<div class='pre p1 fill-light mt0'>andThen(next: function (a: A): <a href="#effresult">EffResult</a>&#x3C;F, B, X>): <a href="#effresult">EffResult</a>&#x3C;any, B, X></div>
Expand Down Expand Up @@ -2833,7 +2832,8 @@ <h3 class='fl m0' id='identity'>
</div>


<p>The Identity monad</p>
<p>The <code>Identity</code> monad</p>
<p>A monad that contains values without any additional behavior</p>


<div class='pre p1 fill-light mt0'>new Identity()</div>
Expand Down Expand Up @@ -2872,7 +2872,8 @@ <h3 class='fl m0' id='identity'>



<p>of :: a -> Identity a</p>
<p><code>of :: a -> Identity a</code></p>
<p>Returns an <code>Identity</code> instance for the given value</p>


<div class='pre p1 fill-light mt0'>of(a: A): <a href="#identity">Identity</a>&#x3C;A></div>
Expand Down Expand Up @@ -2935,7 +2936,7 @@ <h3 class='fl m0' id='identity'>



<p>lift :: (a -> b) -> Identity a -> Identity b</p>
<p><code>lift :: (a -> b) -> Identity a -> Identity b</code></p>


<div class='pre p1 fill-light mt0'>lift(f: function (a: A): B): any</div>
Expand Down Expand Up @@ -2998,7 +2999,7 @@ <h3 class='fl m0' id='identity'>



<p>lift2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c</p>
<p><code>lift2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c</code></p>


<div class='pre p1 fill-light mt0'>lift2(f: function (a: A, b: B): C): any</div>
Expand Down Expand Up @@ -3061,7 +3062,7 @@ <h3 class='fl m0' id='identity'>



<p>lift3 :: (a -> b -> c -> d) -> Identity a -> Identity b -> Identity c -> Identity d</p>
<p><code>lift3 :: (a -> b -> c -> d) -> Identity a -> Identity b -> Identity c -> Identity d</code></p>


<div class='pre p1 fill-light mt0'>lift3(f: function (a: A, b: B, c: C): D): any</div>
Expand Down Expand Up @@ -3120,85 +3121,23 @@ <h3 class='fl m0' id='identity'>
<div class='py1 quiet mt1 prose-big'>Instance Members</div>
<div class="clearfix">

<div class='border-bottom' id='Identity#constructor'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>constructor(data)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>



<p>Constructs a new Maybe instance</p>


<div class='pre p1 fill-light mt0'>constructor(data: A): void</div>










<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>

<div class='space-bottom0'>
<div>
<span class='code bold'>data</span> <code class='quiet'>(A)</code>

</div>

</div>

</div>






<div class='py1 quiet mt1 prose-big'>Returns</div>
<code>void</code>












</section>

</div>
</div>

<div class='border-bottom' id='Identity#map'>
<div class="clearfix small pointer toggle-sibling">
<div class="py1 contain">
<a class='icon pin-right py1 dark-link caret-right'></a>
<span class='code strong strong truncate'>map(f)</span>
<span class='code strong strong truncate'>map(transform)</span>
</div>
</div>
<div class="clearfix display-none toggle-target">
<section class='p2 mb2 clearfix bg-white minishadow'>



<p>map :: Identity a ~> (a -> b) -> Identity b</p>
<p><code>map :: Identity a ~> (a -> b) -> Identity b</code></p>
<p>Transforms the value in the <code>Identity</code> instance</p>


<div class='pre p1 fill-light mt0'>map(f: function (a: A): B): <a href="#identity">Identity</a>&#x3C;B></div>
<div class='pre p1 fill-light mt0'>map(transform: function (a: A): B): <a href="#identity">Identity</a>&#x3C;B></div>



Expand All @@ -3214,7 +3153,7 @@ <h3 class='fl m0' id='identity'>

<div class='space-bottom0'>
<div>
<span class='code bold'>f</span> <code class='quiet'>(function (a: A): B)</code>
<span class='code bold'>transform</span> <code class='quiet'>(function (a: A): B)</code>

</div>

Expand Down Expand Up @@ -3258,7 +3197,8 @@ <h3 class='fl m0' id='identity'>



<p>andThen :: Identity a ~> (a -> Identity b) -> Identity b</p>
<p><code>andThen :: Identity a ~> (a -> Identity b) -> Identity b</code></p>
<p>Chains the value in the <code>Identity</code> instance with another <code>Identity</code>-producing function</p>


<div class='pre p1 fill-light mt0'>andThen(next: function (a: A): <a href="#identity">Identity</a>&#x3C;B>): <a href="#identity">Identity</a>&#x3C;B></div>
Expand Down Expand Up @@ -3321,7 +3261,8 @@ <h3 class='fl m0' id='identity'>



<p>toString :: Identity a ~> () -> String</p>
<p><code>toString :: Identity a ~> () -> String</code></p>
<p>Returns the string representation of the <code>Identity</code> instance</p>


<div class='pre p1 fill-light mt0'>toString(): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></div>
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
},
"scripts": {
"build": "make clean && make",
"docs": "npm-run-all docs:*",
"docs:html": "documentation build src/** --name $npm_package_name --project-version $npm_package_version -f html -o docs",
"docs:md": "documentation build src/** -f md -o docs/api.md",
"docs": "documentation build src/** --name $npm_package_name --project-version $npm_package_version -f html -o docs",
"flow": "flow",
"test:tap": "BABEL_ENV=test babel-tape-runner $(\\find test | \\grep \\.js)",
"test": "npm run test:tap | tap-diff",
Expand Down
14 changes: 11 additions & 3 deletions src/eff.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Task } from './task';
/**
* The `Eff` monad
*
* Represents synchronous computations which are both dependency-injected and explicitly effectful
* Represents a synchronous computation which is both dependency-injected and explicitly effectful
*/
export class Eff<E: {}, A> {

Expand Down Expand Up @@ -82,6 +82,8 @@ export class Eff<E: {}, A> {

/**
* The `EffResult` monad
*
* Represents a synchronous computation that can succeed or fail, and is both dependency-injected and explicitly effectul
*/
export class EffResult<E: {}, A, X> {

Expand All @@ -98,13 +100,19 @@ export class EffResult<E: {}, A, X> {

/**
* `map :: EffResult e a x ~> (a -> b) -> EffResult e b x`
*
* Transform the result of the `EffResult` if successful,
* otherwise the original `EffResult` is returned
*/
map<B>(f: (a: A) => B): EffResult<E, B, X> {
return new EffResult(env => this.runEff(env).map(f));
map<B>(transform: (a: A) => B): EffResult<E, B, X> {
return new EffResult(env => this.runEff(env).map(transform));
}

/**
* `andThen :: EffResult e a x ~> (a -> EffResult f b x) -> EffResult (e & f) b x`
*
* Chains the result of the `EffResult` to another `EffResult`-producing
* function if successful, otherwise the original `EffResult` is returned.
*/
andThen<F: {}, B>(next: (a: A) => EffResult<F, B, X>): EffResult<E & F, B, X> {
return new EffResult(env => this.runEff(env).andThen(a => next(a).runEff(env)));
Expand Down
35 changes: 24 additions & 11 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,76 @@
import { inspect } from 'util';

/**
* The Identity monad
* The `Identity` monad
*
* A monad that contains values without any additional behavior
*/
export class Identity<A> {

data: A

/**
* Constructs a new Maybe instance
*
* @private
*/
constructor(data: A): void {
this.data = data;
}

/**
* map :: Identity a ~> (a -> b) -> Identity b
* `map :: Identity a ~> (a -> b) -> Identity b`
*
* Transforms the value in the `Identity` instance
*/
map<B>(f: (a: A) => B): Identity<B> {
return Identity.of(f(this.data));
map<B>(transform: (a: A) => B): Identity<B> {
return Identity.of(transform(this.data));
}

/**
* andThen :: Identity a ~> (a -> Identity b) -> Identity b
* `andThen :: Identity a ~> (a -> Identity b) -> Identity b`
*
* Chains the value in the `Identity` instance with another `Identity`-producing function
*/
andThen<B>(next: (a: A) => Identity<B>): Identity<B> {
return next(this.data);
}

/**
* toString :: Identity a ~> () -> String
* `toString :: Identity a ~> () -> String`
*
* Returns the string representation of the `Identity` instance
*/
toString(): string {
return `Identity ${ inspect(this.data) }`;
return `${ inspect(this.data) } :: Identity`;
}

/**
* of :: a -> Identity a
* `of :: a -> Identity a`
*
* Returns an `Identity` instance for the given value
*/
static of(a: A): Identity<A> {
return new Identity(a);
}

/**
* lift :: (a -> b) -> Identity a -> Identity b
* `lift :: (a -> b) -> Identity a -> Identity b`
*/
static lift<A, B>(f: (a: A) => B): * {
return (ma) => ma.andThen(a => Identity.of(f(a)));
}

/**
* lift2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c
* `lift2 :: (a -> b -> c) -> Identity a -> Identity b -> Identity c`
*/
static lift2<A, B, C>(f: (a: A, b: B) => C): * {
return (ma, mb) => ma.andThen(a => mb.andThen(b => Identity.of(f(a, b))));
}

/**
* lift3 :: (a -> b -> c -> d) -> Identity a -> Identity b -> Identity c -> Identity d
* `lift3 :: (a -> b -> c -> d) -> Identity a -> Identity b -> Identity c -> Identity d`
*
*/
static lift3<A, B, C, D>(f: (a: A, b: B, c: C) => D): * {
return (ma: Identity<A>, mb: Identity<B>, mc: Identity<C>) => ma.andThen(a => mb.andThen(b => mc.andThen(c => Identity.of(f(a, b, c)))));
Expand Down
2 changes: 1 addition & 1 deletion test/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ test('Identity', t => {
Util.testLift2(tId, Identity);
Util.testLift3(tId, Identity);

t.equal(Identity.of(42).toString(), 'Identity 42', 'toString');
t.equal(Identity.of(42).toString(), '42 :: Identity', 'toString');
});

0 comments on commit e185060

Please sign in to comment.