Skip to content

Instantly share code, notes, and snippets.

@donnut
Created September 20, 2014 10:45
Show Gist options
  • Save donnut/e43a197f7b245a721020 to your computer and use it in GitHub Desktop.
Save donnut/e43a197f7b245a721020 to your computer and use it in GitHub Desktop.
/// <reference path='dst/ramda.d.ts' />
import R = require('ramda');
import Basic = require('./base');
import Base = Basic.Base;
module Bar {
export function bar(s: string): Base {
return {
step: stepBar(s),
display: displayBar(s)
};
}
var stepBar = R.curry(function(s: string, delta: number): Base {
return bar(s + ' ' + delta.toString());
});
var displayBar = function(s: string): string {
return s;
}
}
export = Bar;
module Base {
export interface Base {
step(i: number): Base;
display: string;
}
}
export = Base;
/// <reference path='dst/ramda.d.ts' />
import R = require('ramda');
import Basic = require('./base');
import Base = Basic.Base;
module Foo {
export function foo(i: number): Base {
return {
step: stepFoo(i),
display: displayFoo(i)
};
}
var stepFoo = R.curry(function(i: number, delta: number): Base {
return foo(i+delta);
});
var displayFoo = function(i: number): string {
return i.toString();
}
}
export = Foo;
/// <reference path='dst/ramda.d.ts' />
import R = require('ramda');
import Basic = require('./base');
import Foo = require('./foo');
import Bar = require('./bar');
import Base = Basic.Base;
function stepAll(l: Base[]): Base[] {
return R.map(function(b: Base) {
return b.step(1);
}, l);
}
function displayAll(l: Base[]) {
return R.map(function(b: Base) {
return b.display;
}, l).join('\n');
}
(function main() {
var l: Base[] = [Foo.foo(0), Bar.bar('')];
var l1 = stepAll(stepAll(l));
console.log(displayAll(l1));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment