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 SHA256 = require("crypto-js/sha256"); | |
class Block { | |
constructor(index, timestamp, data, previousHash = '') { | |
this.index = index; | |
this.previousHash = previousHash; | |
this.timestamp = timestamp; | |
this.data = data; | |
this.hash = this.calculateHash(); | |
this.nonce = 0; |
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 IO(effectFn) { | |
const __val = effectFn; | |
const map = fn => IO(() => fn(__val())); | |
const performUnsafeIO = () => __val(); | |
const chain = fn => IO(() => fn(__val()).performUnsafeIO()); | |
return Object.freeze({ | |
map, | |
chain, | |
performUnsafeIO | |
}); |
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
/** | |
* This short program will encrypt the user password | |
* and insert a new record into a mock database. | |
*/ | |
const Reader = require('fantasy-readers'); | |
const Future = require('fluture'); | |
const R = require('ramda'); | |
const crypto = require('crypto'); | |
// our mock database |
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
import is from './is-util'; | |
/** | |
* Either Monad class (from Functional Programming in JavaScript) | |
*/ | |
class Either { | |
constructor(value) { | |
this._value = value; | |
} | |
get value () { |
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 composeK = (...fns) => | |
fns.reduce((f, g) => (...args) => g(...args).chain(f)); | |
const liftA2 = (f, m1, m2) => m1.map(f).ap(m2); | |
const K = a => b => a; | |
const State = computation => { | |
const map = f => | |
State(state => { |
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
/* | |
* Easing Functions - inspired from http://gizma.com/easing/ | |
* only considering the t value for the range [0, 1] => [0, 1] | |
*/ | |
EasingFunctions = { | |
// no easing, no acceleration | |
linear: function (t) { return t }, | |
// accelerating from zero velocity | |
easeInQuad: function (t) { return t*t }, | |
// decelerating to zero velocity |
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 curry = fn => (...args) => | |
args.length >= fn.length ? fn(...args) : curry(fn.bind(undefined, ...args)) | |
const always = a => b => a | |
const compose = (...fns) => args => fns.reduceRight((x, f) => f(x), args) | |
const getFunctor = x => | |
Object.freeze({ | |
value: 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
function toList(next, reversed) { | |
const arr = []; | |
let value = next(); | |
while (value !== undefined) { | |
if (reversed) { | |
arr.unshift(value); | |
value = next(); | |
} else { | |
arr.push(value); | |
value = next(); |
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
// Utility function for detecting generators. | |
let isGenerator = x => { | |
return Function.isGenerator && | |
Function.isGenerator.call(x) | |
} | |
// Data type represents channel into which values | |
// can be `put`, or `received` from. Channel is | |
// very much like queue where reads and writes are | |
// synchronized via continuation passing. |
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
class TrieNode { | |
constructor(char) { | |
this.char = char; | |
this.validWord = false; | |
this.parent = null; | |
this.children = []; | |
} | |
} | |
class Trie { |
OlderNewer