Reload file
C+x C+v
Open file
C+x C+f
//root data is stored in reducer | |
const rootData = fromJS({ | |
company: [ | |
{ | |
id: 'company_1', | |
name: 'foo', | |
campaign: [ | |
{ | |
id: 'cam_1', | |
name: 'bar', |
// from https://github.com/DrBoolean/Practically-Functional | |
const Box = x => | |
({ | |
chain: f => f(x), | |
map: f => Box(f(x)), | |
fold: f => f(x), | |
inspect: () => `Box(${x})` | |
}) |
find src -name "*.js" | xargs grep "immutable" | |
grep -n "#" -A 2 -B 2 *.md | |
grep -n "#" -C 2 *.md |
{ | |
"parser": "babel-eslint", | |
"extends": [ | |
"eslint:recommended", | |
"plugin:import/errors", | |
"plugin:import/warnings", | |
"prettier" | |
], | |
"plugins": [ | |
"prettier" |
const cons = (a, b) => p => p ? a : b; | |
const car = pair => pair(1); | |
const cdr = pair => pair(0); | |
const shift = xs => x => cons(x, xs); | |
const length = xs => typeof xs === 'function' ? 1 + length(cdr(xs)) : 0; | |
const get = xs => index => index ? get(cdr(xs))(index - 1) : xs; | |
const list1 = cons(1, cons(2, 3)); | |
car(list1); |
// First we need to build data structure pair(a, b) | |
// cons: given a and b, and return a function. | |
// when you pass cons(a, b) as argument to car, it will return a; | |
// if you pass it to cdr, it will return b. | |
const cons = (a, b) => p => p ? a : b; | |
const car = pair => typeof pair === 'function' ? pair(1) : null; | |
const cdr = pair => typeof pair === 'function' ? pair(0) : null; | |
// Now we can build list by chaining pair. | |
// For example, list [1, 2, 3] will be represented as cons(1, cons(2, 3)) |
// At first, we need to build empty map. | |
// Empty map is just a function, it will return undefined when invoked. | |
// When you set new key-value into map, it will wrap a new function around previous map, | |
// and when you get something from map with key, it will pass key to every nested function until it match or hit empty map. | |
const map = () => undefined; | |
const set = map => (key, value) => q => q === key ? value: map; | |
const get = map => key => typeof map === 'function' ? get(map(key))(key) : map; | |
// Demo time! |
#!/usr/bin/env babel-node --optional es7.asyncFunctions | |
/** | |
* This file provided by Facebook is for non-commercial testing and evaluation | |
* purposes only. Facebook reserves all rights not expressly granted. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
const empty = () => y => window.Error("not found error"); | |
const extendSet = (y, val, set) => x => x === y ? val : set(x); | |
const setA = extendSet('a', 3, empty()); | |
setA('a'); // 3 | |
setA('b'); // not fuond error | |
const setA2 = extendSet('b', 4, setA); | |
setA2('a'); // 3 | |
setA2('b'); // 4 |