Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raganwald/supervis.es
https://github.com/raganwald/supervis.es
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/raganwald/supervis.es
- Owner: raganwald
- Created: 2013-04-13T03:16:20.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-04-18T19:57:41.000Z (over 11 years ago)
- Last Synced: 2023-04-12T08:06:58.899Z (over 1 year ago)
- Language: CoffeeScript
- Size: 155 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `supervis.es`
This is some example code that demonstrates extending the `sequence` method that is common to functional programming to absorb some monadic abstractions.
Please use [Github Issues](https://github.com/raganwald/supervis.es/issues) or comment on [Commits](https://github.com/raganwald/supervis.es/commits/master) to provide feedback. All thoughts are welcome.
### yak-shaving
The canonical source code is `coffee-src/supervis.es.coffee`. The code is tested using `npm test`, and a `pretest` script compiles the CoffeeScript to JavaScript in `lib/supervis.es.js`. `jasmine-node` then interprets the specs in the `spec` folder (they're also written in CoffeeScript).
To try it, you'll need node, jasmine-node, CoffeeScript, and their respective dependencies.
### code organization
The key function is `sequence`. In naïve form, `sequence` appears to create a pipeline through a series of unary functions, much like functional composition in reverse:
plusOne = (n) -> n + 1
double = (n) -> n * 2
sequence(plusOne, double, double)(1)
#=> 8If the first argument to `sequence` is an instance of `Supervisor`, then `sequence` will use the Supervisor to wrap and unwrap values along the way. Here is the above example using the `Writer` monad:
plusOne = (n) -> [n + 1, "(#{n}) -> #{n + 1}; "]
double = (n) -> [n * 2, "(#{n}) -> #{n * 2}; "]
sequence(Supervisor.Writer, plusOne, double, double)(1)
#=> [ 8, '(1) -> 2; (2) -> 4; (4) -> 8; ' ]If the first argument isn't a Supervisor instance, `sequence` actually uses the `Identity` monad behind the scenes.
At this time, I've coded up:
1. Identity
2. Maybe
3. Writer
4. List
5. Promise
6. CallbackThe `Promise` monad wraps a ridiculously simple `Promise` implementation. Errors fall through much like the Maybe monad. `Callback` is an implementation of Haskell's infamous "Continuation" monad: You can sequence asynchronous callback functions without ugly nesting.
### feedback wanted
Yes please!
* File a [Github Issue](https://github.com/raganwald/supervis.es/issues)
* Comment on a [Commit](https://github.com/raganwald/supervis.es/commits/master)
* [Fork this](https://github.com/raganwald/supervis.es/fork_select) and issue a Pull RequestThanks!