Skip to content

Commit

Permalink
Merge pull request #23 from bskyb-myersch/master
Browse files Browse the repository at this point in the history
Added perform and performUnsafeIO as aliases for run() and minor bug fix...
  • Loading branch information
cwmyers committed Sep 7, 2013
2 parents b762df3 + e4404fe commit 0f58d71
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/main/javascript/monad.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
bind: function (bindFn) {
return bindFn(this.val)
},
flatMap: function(fn) {
flatMap: function (fn) {
return this.bind(fn)
},
some: function () {
Expand Down Expand Up @@ -95,7 +95,7 @@
bind: function (bindFn) {
return this
},
flatMap: function(fn) {
flatMap: function (fn) {
return this
},
some: illegalStateFunction,
Expand Down Expand Up @@ -133,7 +133,7 @@
bind: function (fn) {
return fn(this.val);
},
flatMap: function(fn) {
flatMap: function (fn) {
return this.bind(fn)
},
ap: function (validationWithFn) {
Expand All @@ -148,7 +148,7 @@
}
return Validation.success(x)
},
cata: function(success, fail) {
cata: function (success, fail) {
return success(this.val)
}

Expand All @@ -171,7 +171,7 @@
return this;
},
flatMap: function (fn) {
return this.bind(fn)
return this.bind(fn)
},
isFail: trueFunction,
isSuccess: falseFunction,
Expand All @@ -192,7 +192,7 @@
acc: function () {
return this;
},
cata: function(success, fail) {
cata: function (success, fail) {
return fail(this.error)
}
};
Expand All @@ -211,37 +211,42 @@
throw "Couldn't find a semigroup appender in the environment, please specify your own append function"
}

var IO = io = window.IO = window.io= function(effectFn) {
var IO = io = window.IO = window.io = function (effectFn) {
return new IO.fn.init(effectFn)
}

IO.fn = IO.prototype = {
init: function(effectFn) {
init: function (effectFn) {
this.effectFn = effectFn;
},
map: function(fn) {
map: function (fn) {
var self = this;
return IO(function() {
return IO(function () {
return fn(self.effectFn())
})
},
flatMap: function(fn) {
flatMap: function (fn) {
var self = this
return IO(function() {
return IO(function () {
return fn(self.effectFn()).run()
});
},
bind: function(fn) {
bind: function (fn) {
return this.flatMap(fn)
},
run: function(effectFn) {
run: function () {
return this.effectFn()
},
perform: function () {
return this.run()
},
performUnsafeIO: function () {
return this.run()
}
}

IO.fn.init.prototype = IO.fn;



return this
}(window || this));
Expand Down

0 comments on commit 0f58d71

Please sign in to comment.