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 then(f, a) { | |
return arguments.length == 1 ? | |
a => then(f, a) : | |
a instanceof Promise ? a.then(f) : f(a); | |
} | |
function toIterator(data) { | |
if (data == null) data = []; | |
if (!data[Symbol.iterator]) data = Object.values(data); | |
return data[typeof data.values == 'function' ? 'values' : Symbol.iterator](); |
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 imageDatas = [{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_0.png","x":0,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_1.png","x":32,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_2.png","x":64,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_3.png","x":96,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_4.png","x":128,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_5.png","x":160,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_6.png","x":192,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_7.png","x":224,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_8.png","x":256,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_9.png","x":288,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_10.png","x":320,"y":0},{"url":"https://1906714720.rsc.cdn77.org/http2/tiles_final/tile_ |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script src="pre.fn.js"></script> | |
<script src="images.js"></script> | |
<style> | |
.container { | |
border: 1px solid black; |
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 map = curry2((f, coll) => | |
coll instanceof Function ? | |
(..._) => f(coll(..._)) | |
: | |
coll instanceof Promise ? | |
coll.then(f) | |
: | |
coll instanceof Map ? | |
reduce((m, [k, v]) => then(val => m.set(k, val), f(v)), new Map, coll.entries()) | |
: |
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 { isMatch } = Functional; | |
console.log( isMatch({ a: 1 }, { a: 1, b: 2 }) ); // true | |
console.log( isMatch([2], [1, 2, 3]) ); // true | |
console.log( isMatch(5, 5) ); // true | |
console.log( isMatch("a", "a") ); // true | |
console.log( isMatch({ a: 1, b: 3 }, { a: 1, b: 2 }) ); // false | |
console.log( isMatch(5, 50) ); // false | |
console.log( isMatch("a", "aaa") ); // false |
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 f2 = a => | |
match (a) | |
.case(1) ( | |
a => a + 10, | |
a => a + 100, | |
a => a + 1000) | |
.case(2) ( | |
a => a + 20, | |
a => a + 200, | |
a => a + 2000) |
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 { match } = Functional; | |
const a = 2; | |
const b = match (a) | |
.case(1) (_=> '1이군요!') | |
.case(2) (_=> '2네요?') | |
.else (_=> '1도 2도 아니군요.'); | |
console.log(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
const isAny = a => a !== undefined; | |
const some = map(isAny, find); | |
log( some(a => a > 2, [1, 2, 4, 5]) ); | |
// true | |
log( some(a => a < 2, [1, 2, 4, 5]) ); | |
// true | |
log( some(a => a > 10, [1, 2, 4, 5]) ); | |
// false |
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 info = { | |
title: "Function", | |
list: new Map([ | |
['map', 'Functor f => (a -> b) - f a -> f b'], | |
['reduce', 'Collection c => ((a, b) -> b) -> b -> c a -> a'] | |
]) | |
}; | |
log( | |
reduce( |
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 { reduce, log } = Functional; | |
const add = (a, b) => a + b; | |
log( reduce(add, [1, 2]) ); // 3 | |
log( reduce(add, 0, [1, 2]) ); // 3 | |
log( reduce(add, 10, [1, 2]) ); // 13 | |
log( reduce(add, 100, { a: 1, b: 2 }) ); // 103 | |
log( reduce(add, 200, new Map([['a', 1], ['b', 2]])) ); // 203 | |
log( reduce(add, 300, new Set([1, 2])) ); // 303 |
OlderNewer