Skip to content

Instantly share code, notes, and snippets.

View tdreyno's full-sized avatar

Thomas Reynolds tdreyno

  • Portland, OR
  • 19:36 (UTC -07:00)
View GitHub Profile
@tdreyno
tdreyno / church.js
Created April 22, 2020 01:34
Basic church encoding in JS
// Lambda calculus: Church 1940-ish
//
// <expression> := <name> | <function> | <application>
// <function> := λ <name>.<expression>
// <application> := <expression><expression>
//
// expression := name | function | application
// function := name => expression
// application := expression(expression)
//
@tdreyno
tdreyno / to.ts
Last active January 9, 2020 17:42
Helper method to make `reduce(to(` be a somewhat awkard way to transform arrays to other types.
export function to<A, T>(fn: (items: A[]) => T) {
return (sum: any, _item: A, index: number, all: A[]): T => {
const isLast = index === all.length - 1;
if (!isLast) {
return sum;
}
return fn(all);
};
export function loadStories(userId: string) {
return Task.map2(
myStories => storiesSharedWithMe =>
({
myStories,
storiesSharedWithMe,
}),
userStories(userId).map(listToLookup),
userSharedStories(userId).map(listToLookup),
@tdreyno
tdreyno / andThen.ts
Last active October 23, 2019 19:53
It's like map, but you get the whole list.
interface Array<T> {
andThen: <U>(this: T[], fn: (items: T[]) => U) => U;
}
Array.prototype.andThen = function<T, U>(this: T[], fn: (items: T[]) => U): U {
return fn(this);
};
@tdreyno
tdreyno / 1-demo.ts
Last active September 25, 2017 23:15
// Vector of number types
const v1 = vector([1, 2, 3, 4]);
console.log(v1.toString());
// Vector of string types
const v2 = vector(["a", "b", "c", "d"]);
console.log(v2.toString());
// Vector of vector types
import React from 'react';
import { stylesheet, css } from '../../util';
import {
MEDIUM_COLOR,
LIGHT_PRIMARY_TEXT_COLOR,
BUTTON_LINK_TYPE,
LIGHT_COLOR,
} from '../../styles';
const STYLES = stylesheet({
import {
StyleSheet,
css as stylesheetToClassNames,
} from 'aphrodite';
import { Map } from 'immutable';
const Prefixer = require('inline-style-prefixer');
import { DEVELOPMENT } from '../config';
const prefixer = new Prefixer({ userAgent: navigator.userAgent });
{
"rules": {
"align": [true, "parameters", "statements"],
"arrow-parens": true,
"class-name": true,
"comment-format": [
true,
"check-space"
],
"curly": true,
const country = (seg) => /^[a-z]{2}$/.test(seg);
const midPrefix = (seg) => /^m|g$/.test(seg);
const midValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const coMidPrefix = (seg) => /^m|g$/.test(seg);
const coMidValue = (seg) => /^[a-zA-Z0-9_]+$/.test(seg);
const darkNews = (seg) => seg === DARK_LABEL;
const year = (seg) => /^[0-9]{4}/.test(seg);
const month = (seg) => /^[0-9]{2}/.test(seg);
const day = (seg) => /^[0-9]{2}/.test(seg);

Keybase proof

I hereby claim:

  • I am tdreyno on github.
  • I am tdreyno (https://keybase.io/tdreyno) on keybase.
  • I have a public key whose fingerprint is 0D56 40C3 629D 4F02 3108 0B9B 5DD3 A3D3 D928 68DE

To claim this, I am signing this object: