Skip to content

Instantly share code, notes, and snippets.

View indongyoo's full-sized avatar
🎯
Focusing

유인동 indongyoo

🎯
Focusing
View GitHub Profile
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]();
@indongyoo
indongyoo / images.js
Created February 16, 2018 13:20
같이 있어야할 images.js
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_
<!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;
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())
:
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
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)
const { match } = Functional;
const a = 2;
const b = match (a)
.case(1) (_=> '1이군요!')
.case(2) (_=> '2네요?')
.else (_=> '1도 2도 아니군요.');
console.log(b);
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
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(
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