Skip to content

Commit

Permalink
Merge pull request #77 from cwmyers/develop
Browse files Browse the repository at this point in the history
Fix Free monad
  • Loading branch information
ulfryk authored Oct 24, 2016
2 parents 605bba8 + cf807e8 commit 06d4854
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Simply download and add to your html pages or we also support [bower]. You can
bower install monet --save

# or to install a specific version
bower install monet#0.9.0-alpha.0
bower install monet#0.9.0-alpha.1
```

### Node installation
Expand All @@ -44,7 +44,7 @@ bower install monet#0.9.0-alpha.0
npm install monet --save

# or to install a specific version
npm install [email protected].0
npm install [email protected].1
```

## A note on types
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monet",
"version": "0.9.0-alpha.0",
"version": "0.9.0-alpha.1",
"main": "src/main/javascript/monet.js",
"ignore": [
"**/.*",
Expand Down
2 changes: 1 addition & 1 deletion dist/monet-pimp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* monet-pimp.js 0.8.10
* monet-pimp.js 0.9.0-alpha.1
*
* This file needs to be included after monet.js
*
Expand Down
2 changes: 1 addition & 1 deletion dist/monet-pimp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 46 additions & 4 deletions dist/monet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Monet.js 0.8.10
* Monet.js 0.9.0-alpha.1
*
* (c) 2012-2016 Chris Myers
* @license Monet.js may be freely distributed under the MIT license.
Expand Down Expand Up @@ -298,7 +298,13 @@
ap: function(list) {
return listAp(this, list);
},
isNEL: falseFunction
isNEL: falseFunction,
toString: function() {
return this.isNil ? "Nil" : "List(" + this.toArray().join(", ") + ")";
},
inspect: function() {
return this.toString();
}
};
List.fn.init.prototype = List.fn;
List.prototype.empty = function() {
Expand Down Expand Up @@ -397,7 +403,13 @@
size: function() {
return this.size_;
},
isNEL: trueFunction
isNEL: trueFunction,
toString: function() {
return "NEL(" + this.toArray().join(", ") + ")";
},
inspect: function() {
return this.toString();
}
};
NEL.fromList = function(list) {
return list.isNil ? None() : Some(NEL(list.head(), list.tail()));
Expand Down Expand Up @@ -494,6 +506,12 @@
return self.flatMap(function(a) {
return fn(a) ? self : None();
});
},
toString: function() {
return this.isSome() ? "Just(" + this.val + ")" : "Nothing";
},
inspect: function() {
return this.toString();
}
};
Maybe.prototype.orJust = Maybe.prototype.orSome;
Expand Down Expand Up @@ -572,6 +590,12 @@
},
toEither: function() {
return (this.isSuccess() ? Right : Left)(this.val);
},
toString: function() {
return (this.isSuccess() ? "Success(" : "Fail(") + this.val + ")";
},
inspect: function() {
return this.toString();
}
};
Validation.fn.init.prototype = Validation.fn;
Expand Down Expand Up @@ -729,6 +753,16 @@
},
toValidation: function() {
return this.isRight() ? Success(this.value) : Fail(this.value);
},
toString: function() {
return this.cata(function(left) {
return "Left(" + left + ")";
}, function(right) {
return "Right(" + right + ")";
});
},
inspect: function() {
return this.toString();
}
};
Either.fn.init.prototype = Either.fn;
Expand Down Expand Up @@ -807,7 +841,9 @@
});
},
bind: function(fn) {
return this.isSuspend ? Suspend(this.functor.map(function(free) {
return this.isSuspend ? Suspend(isFunction(this.functor) ? compose(function(free) {
return free.bind(fn);
}, this.functor) : this.functor.map(function(free) {
return free.bind(fn);
})) : fn(this.val);
},
Expand Down Expand Up @@ -858,6 +894,12 @@
},
equals: function(other) {
return isFunction(other.get) && equals(this.get())(other.get());
},
toString: function() {
return "Identity(" + this.val + ")";
},
inspect: function() {
return this.toString();
}
};
Identity.fn.init.prototype = Identity.fn;
Expand Down
4 changes: 2 additions & 2 deletions dist/monet.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/monet.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"name": "monet",
"description": "Monadic types library for JavaScript",
"version": "0.9.0-alpha.0",
"version": "0.9.0-alpha.1",
"homepage": "https://github.com/cwmyers/monet.js",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/monet-pimp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* monet-pimp.js 0.9.0-alpha.0
* monet-pimp.js 0.9.0-alpha.1
*
* This file needs to be included after monet.js
*
Expand Down
14 changes: 8 additions & 6 deletions src/monet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Monet.js 0.9.0-alpha.0
* Monet.js 0.9.0-alpha.1
*
* (c) 2012-2016 Chris Myers
* @license Monet.js may be freely distributed under the MIT license.
Expand Down Expand Up @@ -978,11 +978,13 @@
},
bind: function (fn) {
return this.isSuspend ?
Suspend(
this.functor.map(
function (free) {
return free.bind(fn)
})) :
Suspend(isFunction(this.functor) ?
compose(function (free) {
return free.bind(fn)
}, this.functor) :
this.functor.map(function (free) {
return free.bind(fn)
})) :
fn(this.val)
},
ap: function (ff) {
Expand Down

0 comments on commit 06d4854

Please sign in to comment.