This file contains hidden or 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
| interface Functor { | |
| fmap: (any) => any; | |
| } | |
| interface Monad extends Functor { | |
| bind: (any) => Monad; | |
| } | |
| interface Maybe extends Monad { | |
| } |
This file contains hidden or 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
| // That’s a slightly different thing. Number in JS are always immutable already | |
| let a = 4; | |
| function getA() { | |
| return a++ | |
| } | |
| let v1 = getA() // v1 = 4 | |
| let v2 = getA() // v1 = 4, v2 = 5 | |
| let v3 = getA() // v1 = 4, v2 = 5, v3 = 6 | |
| // Because the value of the number doesn’t change in place. |
This file contains hidden or 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
| instance Monoid (Endofunctor a) where | |
| append :: (a -> m a) -> (a -> m a) -> (a -> m a)` | |
| append = (>=>) | |
| empty :: (a -> m a) | |
| empty = return |
This file contains hidden or 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
| (partition 2 1 [1, 2, 3, 4, 5]) ;;=> ((1 2) (2 3) (3 4) (4 5)) |
This file contains hidden or 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 unfold = (f, seed) => { | |
| const go = (f, seed, acc) => { | |
| const res = f(seed); | |
| return res ? go(f, res[1], acc.concat([res[0]])) : acc | |
| } | |
| return go(f, seed, []); | |
| } | |
| unfold(x => x < 26 ? [String.fromCharCode(x+65), x + 1] : undefined, 0) // Alphabets in capital letter | |
| const range = (begin, end) => { |
This file contains hidden or 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 Nil = {}; | |
| function _LinkedList(h, t) { | |
| this.head = h; | |
| this.tail = t; | |
| } | |
| const LinkedList = (h, t) => new _LinkedList(h, t); | |
| const newLinkedList = LinkedList(5, LinkedList(7, LinkedList(10, Nil))) |
This file contains hidden or 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 React from 'react'; | |
| import User from './User'; | |
| import { connect } from 'react-redux'; | |
| import { fetchUsers } from '../actions/index'; | |
| import { lifecycle, compose } from 'recompose'; | |
| const enhance = compose( | |
| lifecycle({ | |
| componentDidMount() { | |
| this.props.fetchUsers(); |
This file contains hidden or 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 run = Symbol('run'); | |
| const map = Symbol('map'); | |
| const ask = Symbol('ask'); | |
| const of = Symbol('of'); | |
| const flatmap = Symbol('flatmap'); | |
| Function[of] = function(x) { return _ => x; }; | |
| Function.prototype[flatmap] = function(f) { | |
| return s => f(this(s))(s); |
This file contains hidden or 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
| //repeat :: a -> [a] | |
| var repeat = function(a){ | |
| return [a].concat( repeat(a) ); | |
| } | |
| // take :: Int -> [a] -> [a] | |
| var take = function(n, a){ | |
| if(a.length == 0 || n <= 0 ) return []; | |
| return a[0].concat( take( n - 1, a.slice(1) ) ); | |
| } |
This file contains hidden or 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 { IO } from 'fp-ts/lib/IO' | |
| import * as io from 'fp-ts/lib/IO' | |
| import * as array from 'fp-ts/lib/Array' | |
| import { sequence } from 'fp-ts/lib/Traversable' | |
| const add = (classes: string) => (sel: HTMLElement): IO<HTMLElement> => { | |
| return new IO(() => { | |
| sel.classList.add(classes) | |
| return sel | |
| }) |