This file contains 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
/*eslint-env es6 */ | |
// Inspired by the paper "A tutorial on the universality and | |
// expressiveness of fold" by Graham Hutton (available at | |
// http://www.cs.nott.ac.uk/~gmh/fold.pdf), implementing some generic | |
// list handling functions in JavaScript in terms of `fold`. | |
// Personally I had an enlightnening moment when I realised the | |
// beautiful interplay of cons lists and foldr during the FP101x | |
// Haskell course. JavaScript's syntax doesn't make this very apparent |
This file contains 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
//scala | |
vertx.createHttpServer().requestHandler({ req: HttpServerRequest => | |
req.response() | |
.putHeader("Content-Type", "text/html") | |
.end("<html><body><h1>Hello from Vert.x!" + | |
"</h1></body></html>") | |
}).listen(8080) | |
//groovy | |
vertx.createHttpServer().requestHandler({ req -> |
This file contains 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
Verifying that +srdjan is my openname (Bitcoin username). https://onename.com/srdjan |
This file contains 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
//pseudo code... not compiling | |
var h = Cycle.h | |
var FooModel = Cycle.createModel(intent => | |
{ /*...*/ } | |
) | |
var FooView = Cycle.createView(model => | |
{ /*...*/ } | |
) | |
var FooIntent = Cycle.createIntent(view => | |
{ /*...*/ } |
This file contains 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
static void Main(string[] args) { | |
//-1) Maybe monad usage: input regular string, intermediate result int... | |
var maybeM = new MaybeM<string>("I'm a string, wrapped up in the Maybe Monad!"); | |
var result1 = maybeM.Bind(ExtractVowels) | |
.Bind(Length); | |
WriteLine("Result is: \{result1.Show()}"); | |
//-2) Maybe monad usage: null string | |
maybeM = new MaybeM<string>(null); | |
var result2 = maybeM.Bind(ExtractVowels) |
This file contains 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
//-- monad interface | |
//-- | |
public interface IMonad<T> { | |
//IMonad<T> From(T @value);//note: implemented as constructor | |
IMonad<T2> Bind<T2>(Func<T, T2> f) where T2 : class; | |
// simple access the wrapped value(s), optional but helpfull :) | |
string Show(); | |
} |
This file contains 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 service = require('resto.service'); | |
var pipeline = require('resto.pipeline'); | |
var http = require('resto.httpserver'); | |
var authenticator = require('resto.middleware.authn'); | |
var authorizer = require('resto.middleware.authr'); | |
var resolver = require('resto.middleware.resolver'); | |
var invoker = require('resto.middleware.invoker'); | |
var converter = require('resto.middleware.hal'); | |
//- dsl | |
var withMany = require('resto.realtionships').hasMany; |
This file contains 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 Either = require('data.either'); | |
var log = console.log; | |
var handlers = []; | |
function use(f, p, t) { | |
handlers.push({ func: f, pred: p || false, trace: t || false}); | |
} | |
// f, ep, m(a) -> m(b) |
This file contains 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 run(ctx) { | |
var i; | |
for(i=0; i<stash.length; i++) { | |
if(logBefore) { | |
trace(stash[i], ctx); | |
} | |
stash[i](ctx); | |
if(logAfter) { | |
trace(stash[i], ctx); | |
} |
This file contains 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
// original code | |
function printTrace(log) { | |
for (var i = 0; i < log.length; i++) { | |
var entry = log[i]; | |
var args = entry.args; | |
var argstring = "("; | |
for (var j = 0; j < args.length - 1; j++) { | |
argstring += args[j].toString() + ","; | |
} | |
if (args.length > 0) { |