https://github.com/f/puremise.js
Yet another purely functional Promise Monad implementation
https://github.com/f/puremise.js
Last synced: 8 months ago
JSON representation
Yet another purely functional Promise Monad implementation
- Host: GitHub
- URL: https://github.com/f/puremise.js
- Owner: f
- Created: 2013-11-03T07:54:31.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-05-30T07:23:51.000Z (about 10 years ago)
- Last Synced: 2025-02-01T07:23:07.856Z (over 1 year ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
puremise.js
===========
Yet another purely functional Promise Monad implementation. I tried to implement it obeying functional programming rules.
[Implementation Details in Turkish](http://blog.fatihak.in/fonksiyonel-programlama-notlari-promise-monad-pure-functional/)
## Examples
```javascript
x = Promise(function () {
console.log("x resolved");
})
x.success(function () {
console.log("x resolved again..");
});
x.success(function () {
console.log("x resolved again and again..");
});
y = Promise().success(function () {
console.log("y resolved");
});
y.fail(function () {
console.log("y rejected");
});
When([x, y]).success(function () {
console.log("x and y all resolved");
});
```
Resolve the promises:
```javascript
x.resolve(); //=> "x resolved", "x resolved again..", "x resolved again and again.."
y.resolve(); //=> "y resolved", "x and y all resolved"
```
And it can be rejected, too:
```javascript
When([x, y]).success(function () {
console.log("x and y all resolved");
}).fail(function () {
console.log("something rejected!");
});
y.reject(); //=> "something rejected!"
```
## Async Usage
```javascript
function defer() {
var deferred = Promise();
setTimeout(deferred.resolve, 1000);
return deferred;
}
defer().success(function () {
console.log("this will be resolved after 1 sec.!");
});
// after 1 sec: => "this will be resolved after 1 sec.!"
```
## License
MIT License