Skip to content

Instantly share code, notes, and snippets.

View rbuckton's full-sized avatar

Ron Buckton rbuckton

View GitHub Profile
'use strict';
class MapAsyncIterable<T, R> implements AsyncIterable<R> {
private _source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>;
private _selector: (value: T) => R | PromiseLike<R>;
constructor(source: Iterable<T | PromiseLike<T>> | AsyncIterable<T>, selector: (value: T) => R | PromiseLike<R>) {
this._source = source;
this._selector = selector;
}
@rbuckton
rbuckton / git-checkout-pr
Last active June 1, 2017 23:22
Performs a fetch and checkout of a github pull request.
#!/bin/sh
source "$(git --exec-path)/git-sh-setup"
USAGE="<pull> [<branch>]"
function _pr() {
if [[ -n $(git rev-parse --verify --quiet $2) ]]; then
git checkout $2
else
git fetch origin pull/$1/head:$2
@rbuckton
rbuckton / example.ts
Last active June 15, 2017 22:32 — forked from mattpodwysocki/example.ts
Reimagining events as async iterables
const EventEmitter = require('events').EventEmitter;
const fromEventPattern = require('ix/asynciterable/fromeventpattern').fromEventPattern;
// Get Async Iterable
const e = new EventEmitter();
const ai = fromEventPattern(
h => e.addListener('data', h),
h => e.removeListener('data', h)
);
@rbuckton
rbuckton / CreateDateTable.m
Created June 26, 2017 21:49
PowerQuery function to create a Date dimension table
let
CreateDateTable = (StartDate as date, EndDate as date, optional Culture as nullable text) as table =>
let
Today = DateTime.Date(DateTime.FixedLocalNow()),
#"Start Of Month" = Date.StartOfMonth(Today),
#"30 Days Ago" = DateTime.Date(Today - #duration(30, 0, 0, 0)),
#"60 Days Ago" = DateTime.Date(Today - #duration(60, 0, 0, 0)),
#"90 Days Ago" = DateTime.Date(Today - #duration(90, 0, 0, 0)),
#"12 Months Prior" = #date(Date.Year(#"Start Of Month") - 1, Date.Month(#"Start Of Month") + 1, 1),
#"Number of Days" = Duration.TotalDays(Date.StartOfDay(EndDate) - Date.StartOfDay(StartDate)),

High-Order Type Relationships for promised T

Definitions

  1. Definition - A type T is promise-Like iff T has a callable then method that accepts a function as its first argument.

  2. Definition - The fulfillment type of T is the type V in T.then((value: V) ⇒> {}).

  3. Definition - The promised type of T (nee. promised T) is the promised type of the fulfillment type of T iff T is promise-like; otherwise, T.

const obj = {
  y: 1,
  method(x) => x + this.y,
  get prop() => this.y,
  set prop(v) => this.y = v
}

class C {
 y = 1;

Exploration of Statements as Expressions

For the purposes of this investigation, I am breaking down the various statements within ECMAScript into several broad categories:

  • Leaf Statements:
    • Declaration Statements - class, function, var, let, const, import, export
    • Abrupt Completion Statements - throw, return, break, continue
    • Other - debugger
  • Branching Statements:
  • Control Flow Statements - if, switch, try
const nodeFriend = new FriendKey();
export class LinkedList {
#head;
#size;
get first() { return this.#head; }
get last() { return this.#head !== undefined ? nodeFriend.get(this.#head, "#previous") : undefined; }
get size() { return this.#size; }