This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var util = require("util"); | |
| var Cons = function(a,b) { | |
| var cons = function(fn) { return fn(a,b); }; | |
| return cons; | |
| }; | |
| var Car = function(cons) { | |
| var car = function(a,b) { return a; }; | |
| return cons(car); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mc = require("mongodb").MongoClient | |
| mc.connect("mongodb://localhost:27017/school", function(err, db) { | |
| if (err) { | |
| return console.error(err); | |
| } | |
| /* | |
| db.collection("students").find({}).toArray(function(err, students) { | |
| if (err) { | |
| return console.error(err); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //node --harmony b.js | |
| "use strict"; | |
| var b = [1,20,1000].map(e => e+100) | |
| b.forEach(e => console.log(e)); | |
| if( true) { | |
| let b = "spartaaa"+12; | |
| console.log(b); | |
| } | |
| b.forEach(e => console.log(e)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function whatDoesItDo(val){ | |
| return val ? 1 : 2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bash-3.2$ echo '{ "name": "Foo", "phone": "555-1212", "email": "[email protected]", "id": 123 }' | node b.js | |
| [{"name":"Foo","id":123}]:buffer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Stream = require("stream"); | |
| var stream = new Stream(); | |
| stream.readable = true; | |
| var i = 0; | |
| var x = setInterval(function() { | |
| stream.emit("data", "."+i); | |
| i+= 1; | |
| }, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Cons cells are functions! But they're also data structures! | |
| def cons(head, tail) : | |
| def _(fn): | |
| return fn(head, tail) | |
| return _ | |
| # imperative version cns.head if cns was a struct/ tuple | |
| def head(cns) : | |
| return cns(lambda head, tail : head) | |
| def tail(cns): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data = '''a narrow fellow in the grass | |
| occasionally rides; | |
| you may have met him, did you not, | |
| his notice sudden is. | |
| the grass divides as with a comb, | |
| a spotted shaft is seen; | |
| and then it closes at your feet | |
| and opens further on. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var mongodb = require("mongodb"); | |
| var MongoClient = mongodb.MongoClient; | |
| var fs = require("fs"); | |
| var Transform = require("stream").Transform; | |
| var name_surname_email_filter = new Transform({readableObjectMode:true, writableObjectMode:true} ); | |
| name_surname_email_filter._transform = function(data, enc, cb) { | |
| //console.log(data); | |
| var newdata = { first_name: data.first_name, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * | |
| * Functor : | |
| * fmap : (a -> b) -> fa -> fb | |
| * | |
| */ | |
| function array_fmap1(fn, typeA) { | |
| var typeB = [] | |
| typeA.forEach(function(aVal) { |