(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| ;; -*- mode: emacs-lisp -*- | |
| ;; This file is loaded by Spacemacs at startup. | |
| ;; It must be stored in your home directory. | |
| (defun dotspacemacs/layers () | |
| "Configuration Layers declaration. | |
| You should not put any user code in this function besides modifying the variable | |
| values." | |
| (setq-default | |
| ;; Base distribution to use. This is a layer contained in the directory | 
| use std::boxed::Box; | |
| use std::option::Option; | |
| use std::result::Result; | |
| use Maybe::*; | |
| #[derive(Debug, PartialEq, Eq)] | |
| enum Maybe<T> { | |
| Nothing, | |
| Just(T), | |
| } | 
| // Reference from: https://play.rust-lang.org/?gist=a571361967dc228330b3&version=stable | |
| trait Shape { | |
| fn draw(&self); | |
| } | |
| struct Square; | |
| impl Shape for Square { | |
| fn draw(&self) { println!("Square drawn."); } | |
| } | 
| let everythingIsDone = Rx.Observable.fromEvent(em, ‘everythingIsDone’); | |
| let eventSource = Rx.Observable.fromEvent(em, ‘event’).takeUntil(everythingIsDone).toArray().toPromise(); | 
| function multiBy10(n) { | |
| // Setup a base return | |
| if (n <= 1) | |
| return 10 | |
| // Loop recursive here | |
| else | |
| return 10 + multiBy10(n-1) | |
| } | |
| /** | 
| // Provided that `request()` is a promise | |
| function *something() { | |
| var text1 = yield request('url1') | |
| var text2 = yield request('url2') | |
| var text3 = yield request('url3') | |
| } | |
| var it = something() // Start the something() generator | 
| // Reference from: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/howdoi/eventemitter.md | |
| var hasOwnProp = {}.hasOwnProperty; | |
| function createName (name) { | |
| return '$' + name; | |
| } | |
| function Emitter() { | |
| this.subjects = {}; | 
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| // Functors apply a function to a wrapped value and then return a wrapped value | |
| // Functors are chainable | |
| // Functor::(a -> b) -> f(a) -> f(b) | |
| class Wrapper { | |
| constructor(val) { | |
| console.log('Created a wrapped value ' + val); | |
| this.val = val; | |
| } | |
| // Functor's `fmap` in Haskell | |
| map(func) { | 
| // Taken from: http://es-discourse.com/t/partial-default-arguments/120/7 | |
| var defaults = { | |
| options: { | |
| remove: true, | |
| enable: false, | |
| instance: {} | |
| }, | |
| log: { | |
| warn: true, |