EventStream:

You can use RxJS, BaconJS or any reactive programming lib you want:

var id_s = map(function(e) { return  '#'+e.id }, Bacon.fromEventTarget(document, "click"))
var element_s = map(document.querySelector, id_s)
//=> EventStream(Element) element_s.onValue(function(el) { alert('The inner html is ' +el.innerHTML) })

Here using BaconJS; we need to call onValue to subscribe stream.

Future:

It is "lazy", you must fork it.

var makeHtml = function(post){ return "<div>"+post.title+"</div>"};
var page_f = map(makeHtml, http.get('/posts/2')) page_f.fork(function(err) { throw(err) },
function(page){ $('#container').html(page) })
console.clear();
var _ = R;
var P = PointFree;
var map = P.fmap;
var compose = P.compose;
var Maybe = P.Maybe;
var Identity = P.Id; // Exercise 1
// ==========
// Use _.add(x,y) and map(f,x) to make a function that increments a value inside a functor
console.log("--------Start exercise 1--------") var ex1 = map(_.add()) assertDeepEqual(Identity(), ex1(Identity()))
console.log("exercise 1...ok!") // Exercise 2
// ==========
// Use _.head to get the first element of the list
var xs = Identity(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
console.log("--------Start exercise 2--------") var ex2 = map(_.head); assertDeepEqual(Identity('do'), ex2(xs))
console.log("exercise 2...ok!") // Exercise 3
// ==========
// Use safeGet and _.head to find the first initial of the user
var safeGet = _.curry(function(x,o){ return Maybe(o[x]) })
var user = {id: , name: "Albert"}
console.log("--------Start exercise 3--------") var ex3 = compose(map(_.head), safeGet('name')); assertDeepEqual(Maybe('A'), ex3(user))
console.log("exercise 3...ok!") // Exercise 4
// ==========
// Use Maybe to rewrite ex4 without an if statement
console.log("--------Start exercise 4--------") var ex4 = function(n) {
if(n){
return parseInt(n);
}
} var ex4 = compose(map(parseInt),Maybe) assertDeepEqual(Maybe(), ex4(""))
console.log("exercise 4...ok!") // TEST HELPERS
// =====================
function inspectIt(x){
return (x.inspect && x.inspect()) || (x.toString && x.toString()) || x.valueOf(); //hacky for teachy.
} function assertEqual(x,y){
if(x !== y){ throw("expected "+x+" to equal "+y); }
}
function assertDeepEqual(x,y){
if(x.val !== y.val) throw("expected "+inspectIt(x)+" to equal "+inspectIt(y));
}

最新文章

  1. K 均值算法(K-means)
  2. JS中的闭包
  3. ffmpeg-20160726-bin.7z
  4. Farey Sequence
  5. tyvj 1056 能量项链 区间dp (很神)
  6. grep 与正则表达式
  7. SVN与TortoiseSVN实战:属性的奇技淫巧(二)
  8. Go语言工程结构
  9. Android渲染机制和丢帧分析
  10. asp.net中对象的序列化,方便网络传输
  11. hadoop的wordcount的改动版
  12. 运用MyEclipse插件(link方式注意点)
  13. 从零开始,使用python快速开发web站点(1)
  14. 面向对象的特性-利用prototype为类创建静态成员
  15. PAT (Advanced Level) 1058. A+B in Hogwarts (20)
  16. 基于Redis位图实现系统用户登录统计
  17. python 中常见绘图属性
  18. Universal-Image-Loader完全解析--从源代码分析Universal-Image-Loader中的线程池
  19. [Swift]LeetCode470. 用 Rand7() 实现 Rand10() | Implement Rand10() Using Rand7()
  20. 更新下载库update绝对详解

热门文章

  1. Js原型模式
  2. windows远程连接linux桌面---使用tightvnc或者tigervnc
  3. 3. 使用绘图API自定义视图 --- 旋转的方块
  4. &lt;转&gt;亲手缔造DNS体系,创建DNS私有根:DNS系列之六
  5. TRANSLATE
  6. pci 记录
  7. Codeforces Round #362
  8. MFC工程目录
  9. Binder机制
  10. hdfs[命令] dfs