Skip to content

Instantly share code, notes, and snippets.

View baetheus's full-sized avatar

Brandon Blaylock baetheus

View GitHub Profile
@baetheus
baetheus / compose.ts
Created April 21, 2021 00:36
Functor Composition with nullpub/hkts
import type { Kind, URIS } from "./hkt.ts";
import type * as TC from "./type_classes.ts";
import { flow, pipe } from "./fns.ts";
export type FunctorComposition<URI extends URIS, VRI extends URIS> = {
readonly map: <A, I>(
fai: (a: A) => I,
) => <B, C, D, E, F, G>(
ta: Kind<URI, [Kind<VRI, [A, B, C, D]>, E, F, G]>,
) => Kind<URI, [Kind<VRI, [I, B, C, D]>, E, F, G]>;
@baetheus
baetheus / schemable.ts
Created March 21, 2021 02:37
Minimal Schemable Example
/*******************************************************************************
* Kinds Type
* @description A registry for Kind URIS with their substitution strategies.
* Note that the idiomatic replacement type for kinds uses _0 as the inner-
* most hole for Functor and Chain. Thus Either<L, R> should use the hole
* order of Either<_1, _0>. This is reflected in the replacement strategies
* used in type_classes.ts
******************************************************************************/
export interface Kinds<A, B, C, D> {
@baetheus
baetheus / hkt.ts
Last active March 24, 2021 17:36
expanding pelotom hkts with kind substitution map
/*******************************************************************************
* Kinds Type
*
* A registry for Kind URIS with their substitution strategies.
* Note that the idiomatic replacement type for kinds uses $[0] as the inner-
* most hole for Functor and Chain. Thus Either<L, R> should use the hole
* order of Either<$[1], $[0]>.
*
* Here $ is a tuple of types that can be substituted into each kind.
******************************************************************************/
@baetheus
baetheus / hkt_substitution.ts
Last active March 1, 2021 05:58
Combination of pelotom hkts and fpts HKT
// Option
export type None = { tag: "None" };
export type Some<A> = { tag: "Some"; value: A };
export type Option<A> = None | Some<A>;
// Either
@baetheus
baetheus / stream.ts
Last active December 26, 2020 07:26
A 15 minute start at observable/callbag/most streams for Deno
import type * as TC from "https://deno.land/x/hkts/type_classes.ts";
import type { _, Fn } from "https://deno.land/x/hkts/types.ts";
import { pipe } from "https://deno.land/x/hkts/fns.ts";
enum Signal {
Open,
Ready,
Pause,
Drain,
Close,
_________________________________________
/ On the other hand, the TCP camp also \
| has a phrase for OSI people. There are |
| lots of phrases. My favorite is |
| `nitwit' -- and the rationale is the |
| Internet philosophy has always been you |
| have extremely bright, non-partisan |
| researchers look at a topic, do |
| world-class research, do several |
| competing implementations, have a |
@baetheus
baetheus / main.ts
Created September 29, 2020 03:09
Deno with sedate
import { serve } from "https://deno.land/std/http/server.ts";
import { connect } from "https://deno.land/x/[email protected]/mod.ts";
import { use } from "https://deno.land/x/[email protected]/deno_handler.ts";
import * as S from "https://deno.land/x/[email protected]/sedate.ts";
import { pipe } from "https://deno.land/x/[email protected]/fns.ts";
const nil = <A>(a: A): a is NonNullable<A> => a === undefined && a === null;
const PORT = Deno.env.get("PORT");
const REDIS_URL = Deno.env.get("REDIS_URL");
@baetheus
baetheus / models.ts
Last active June 18, 2020 05:42
Damped Harmonic Motion - See @nll/motion for further work
/**
* @since 0.0.0
*/
/**
* @since 0.0.0
*/
export interface SpringConfig {
mass: number;
tension: number;
@baetheus
baetheus / fp_ts.ts
Last active May 17, 2020 21:21
Deno Oak adapter for hyper-ts
export * from "https://cdn.pika.dev/fp-ts@^2.6.1";
@baetheus
baetheus / createStateRestore.ts
Last active May 14, 2020 22:38
A localstorage manager for use with @nll/dux/Store
import * as C from "io-ts/es6/Codec";
import * as E from "fp-ts/es6/Either";
import { draw } from "io-ts/es6/Tree";
import { pipe } from "fp-ts/es6/pipeable";
import { actionCreatorFactory, AsyncActionCreators } from "@nll/dux/Actions";
import { asyncConcatMap } from "@nll/dux/Operators";
import { RunOnce, filterEvery, RunEvery, Store } from "@nll/dux/Store";
import { of, Observable, throwError, interval } from "rxjs";
import { mergeMap, map } from "rxjs/operators";