Skip to content

Instantly share code, notes, and snippets.

View joshburgess's full-sized avatar
💭
🤔

Josh Burgess joshburgess

💭
🤔
View GitHub Profile
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
@joshburgess
joshburgess / bidirectional-structural.ts
Created July 25, 2018 15:29 — forked from gelisam/bidirectional-structural.ts
bidirectional type-checker in TypeScript
// in response to https://twitter.com/arntzenius/status/1022076441603829760
// types A,B ∷= base | A → B
// terms M ∷= E | λx.M
// exprs E ∷= x | E M | (M : A)
type Type = "Base" | {lhs: Type, tag: "->", rhs: Type};
type Var = string;
type Term = Expr | {tag: "Lam", varname: Var, body: Term};
type Expr = Var | {tag: "App", fn: Expr, arg: Term} | {term: Term, tag: ":", tp: Type};
@joshburgess
joshburgess / foo.ts
Created June 27, 2018 02:23 — forked from OliverJAsh/foo.ts
Type safe routing with `fp-ts-routing` and `unionize`
import {
end,
int,
lit,
Match,
parse,
Route as RouteBase,
zero
} from "fp-ts-routing";
import { pipe } from "fp-ts/lib/function";
@joshburgess
joshburgess / Ref.js
Created June 24, 2018 08:50 — forked from maddie927/Ref.js
react-basic Ref component
"use strict";
var React = require("react");
var ReactDOM = require("react-dom");
exports.makeRef = function(toMaybe) {
var Ref = function(props) {
this.DOMNode = null;
return this;
};
@joshburgess
joshburgess / DictTrick.hs
Created May 25, 2018 15:20 — forked from jship/DictTrick.hs
Small example showing the Dict trick to discover available instances from a GADT
#!/usr/bin/env stack
-- stack --resolver lts-10.8 --install-ghc exec ghci
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
-- A key type for pretend use in looking up a doggo in a database.
newtype Key a = Key { unKey :: String }
@joshburgess
joshburgess / hkt.rs
Created May 18, 2018 06:37 — forked from 14427/hkt.rs
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@joshburgess
joshburgess / README.md
Created May 9, 2018 22:35 — forked from dwhitney/README.md
Quick React Native with PureScript
  1. create-react-native-app purescript-app; cd purescript-app

  2. pulp init --force

  3. pulp build

  4. src/Main.js

var React = require("react");
var RN = require("react-native");

exports.text = function(props){
@joshburgess
joshburgess / ramda-sanctuary.md
Created March 6, 2018 22:06 — forked from Avaq/ramda-sanctuary.md
Comprehensive Ramda to Sanctuary list
Ramda Sanctuary
add(a, b) add(b, a)
addIndex(f) ``
adjust(f, i, xs) ``
all(f, xs) ``
allPass(fs, x) allPass(fs, x)
always(x) K(x)
and(a, b) and(a, b)
any(f, x) ``

The future is here: Classless object-oriented programming in JavaScript.

Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.

Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.

I think it's really, really sleek, and this is what it looks like:

function dog(spec) {
@joshburgess
joshburgess / articles.md
Created February 15, 2018 07:45 — forked from miwillhite/articles.md
Functional JavaScript (and other)