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 listNode(value, next) { | |
return { | |
value: value, | |
next: next | |
}; | |
} | |
var three = listNode(3); | |
var two = listNode(2, three); | |
var one = listNode(1, two); |
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 linkedList = listNode(1, listNode(2, listNode( 3))); | |
linkedList.map(function(x) { | |
return x + 1; | |
}); | |
// listNode(2, listNode(3, listNode( 4))); |
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 treeNode(value, left, right) { | |
return { | |
value: value, | |
left: left, | |
right: right | |
}; | |
} | |
var myTree = treeNode(1, treeNode(2), treeNode(3)); |
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 treeNode(value, left, right) { | |
return { | |
value: value, | |
left: left, | |
right: right, | |
map: function(transformation) { | |
var nextValue = transformation(nextValue); | |
var nextLeft; | |
if (left) nextLeft = left.map(transformation); |
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 tree = treeNode(1, treeNode(2), treeNode(3)); | |
tree.map(function(x) { | |
return x + 1; | |
}); | |
// treeNode(2, treeNode(3), treeNode(4)) |
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 identity(x) { return x; } |
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
[1, 2, 3].map(identity); | |
// [1, 2, 3] | |
listNode(1, listNode(2, listNode(3))).map(identity); | |
// listNode(1, listNode(2, listNode(3))) | |
treeNode(1, treeNode(2), treeNode(3)).map(identity); | |
// treeNode(1, treeNode(2), treeNode(3)) |
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 addOneAndMultiplyTwo(x) { return multiplyTwo(addOne(x)); } | |
[1, 2, 3].map(addOneAndMultiplyTwo); | |
listNode(1, listNode(2, listNode(3))).map(addOneAndMultiplyTwo); | |
treeNode(1, treeNode(2), treeNode(3)).map(addOneAndMultiplyTwo); |
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 map(transformation, data) { | |
return data.map(transformation); | |
} | |
map(addOne, [1, 2, 3]); | |
map(addOne, listNode(1, listNode(2, listNode(3)))); | |
map(addOne, treeNode(1, treeNode(2), treeNode(3))); |
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
const { find, identity, toPairs, compose, map, curry } = require('ramda'); | |
/* tslint:disable: no-any */ | |
type AnyType = any; | |
/* tslint:enable: no-any */ | |
type TComparator = (a: AnyType, b: AnyType) => number; | |
type TObjectComparator = { | |
[key: string]: TComparator; |