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 dotenv = require('dotenv'); | |
| dotenv.config(); | |
| const jsdom = require("jsdom"); | |
| const { JSDOM } = jsdom; | |
| const dom = new JSDOM(`<!DOCTYPE html><html><body></body></html>`); | |
| global.document = dom.window.document; | |
| global.window = document.defaultView; |
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 Connect from "../connect"; | |
| const initialState = { | |
| isActive: false | |
| }; | |
| const toggle = state => Object.assign({}, state, { isActive: !state.isActive }); | |
| const updaters = { |
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
| // Keep it simple | |
| import React from 'react'; | |
| import { render } from 'react-dom'; | |
| import hoistNonReactStatic from 'hoist-non-react-statics'; | |
| const increment = multiply => ({ counter }, { step }) => ({ | |
| counter: counter + step * multiply, | |
| }); |
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' | |
| // Comp:: a -> JSX; | |
| const Comp = g => ({ | |
| fold: g, | |
| contramap: f => Comp(x => g(f(x))), | |
| concat: other => Comp((x) => <div> {g(x)} {other.fold(x)} </div>) | |
| }); | |
| // Reducer :: (a, b) -> a |
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 { render } from "react-dom"; | |
| import R from "ramda"; | |
| const users = [ | |
| { id: 1, name: "foo", points: 45 }, | |
| { id: 2, name: "bar", points: 22 }, | |
| { id: 3, name: "baz", points: 79 }, | |
| { id: 4, name: "bla", points: 54 } | |
| ]; |
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
| // | |
| // product types | |
| // | |
| /* | |
| // A coordinate in 3D space | |
| export type Coord = { | |
| readonly x: number | |
| readonly y: number | |
| readonly z: number |
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
| /* Slaying a UI Anti Pattern in Reason */ | |
| type remoteData 'e 'a = | |
| | Nothing | |
| | Loading | |
| | Failure 'e | |
| | Success 'a; | |
| type item = { | |
| userId: int, |
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
| /* | |
| Type Tac Toe: Advanced Type Safety | |
| ================================== | |
| Adapted from http://chrispenner.ca/posts/type-tac-toe | |
| */ | |
| /** Either X, O, or Nothing */ | |
| type Piece = 'X' | 'O' | 'N' | |
| /** coordinates */ |
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
| // Typescript can handle monomoprhic functions | |
| const flip = <A, B, C>(f: (a: A) => (b: B) => C): ((b: B) => (a: A) => C) => b => a => f(a)(b) | |
| const foo = (a: string) => (b: number) => a.length - b | |
| // fooFlipped: (b: number) => (a: string) => number | |
| const fooFlipped = flip(foo) | |
| // But can't handle polymorphic functions | |
| const concat = <A>(xs: Array<A>) => (a: A): Array<A> => xs.concat([a]) |
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
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE ScopedTypeVariables #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| module CCCs where |