Skip to content

Instantly share code, notes, and snippets.

View baetheus's full-sized avatar

Brandon Blaylock baetheus

View GitHub Profile
@baetheus
baetheus / #note.md
Last active December 23, 2022 17:59
Kliesli Arrow Optics

This implementation can now be found in production here

@baetheus
baetheus / action.ts
Last active October 21, 2022 14:45
New dux simplified interfaces
/**
* An action is the standard action that most
* applications deal with. It is typed, like TypedAction, but
* also has a payload associated with it.
*/
export type Action<P = void> = {
readonly tag: string;
readonly payload: P;
};
@baetheus
baetheus / lazy.ts
Last active October 14, 2022 23:25
A quick pass at lazy computation in typescript.
/**
* This is a quick attempt at a stack safe version
* of Fn. The unfortunate bit is that it relies on a
* central class for building and executing a lazy..
*
* It's probably easy enough to create a typed tuple
* where we only track the input of the first control
* and the return of the last control. That's something
* to look into.
*
@baetheus
baetheus / tagged.ts
Last active September 18, 2022 23:47
Playing around with a generic tagged error
// deno-lint-ignore-file no-explicit-any
import * as RSS from "https://deno.land/x/rss@0.5.6/mod.ts";
import * as TE from "https://raw.githubusercontent.com/baetheus/fun/main/task_either.ts";
import { pipe } from "https://raw.githubusercontent.com/baetheus/fun/main/fns.ts";
// ---
// Try implementing a reusable error type
// ---
export type TaggedError<T extends string, A> = {
@baetheus
baetheus / actions.ts
Last active August 24, 2022 02:40
Rehashing Flex Standard Action Creators
/**
* An action is the standard action that most
* applications deal with. It is typed, like TypedAction, but
* also has a payload associated with it.
*/
export type Action<P = void, T extends string = string> = {
readonly tag: T;
readonly payload: P;
};
@baetheus
baetheus / effect.ts
Last active August 24, 2022 03:24
briancavalier fx but in deno
// See https://github.com/briancavalier/fx
export type Effect<T, A, R> = {
type: T;
arg: A;
[Symbol.iterator](): Generator<Effect<T, A, R>, R, R>;
};
export function effect<T, A, R>(type: T, arg: A): Effect<T, A, R> {
return {
@baetheus
baetheus / compose.ts
Last active August 31, 2022 22:55
Working general compose with narrowing "never" on incorrect usage
// deno-fmt-ignore-file no-explicit-any
import type { Iso } from "./iso.ts";
import type { Lens } from "./lens.ts";
import type { Prism } from "./prism.ts";
import type { Optional } from "./optional.ts";
import type { Traversal } from "./traversal.ts";
import * as I from "./iso.ts";
import * as L from "./lens.ts";
@baetheus
baetheus / iterable.ts
Created August 30, 2021 17:57
Playing with Iterable/AsyncIterable
import type * as HKT from "./hkt.ts";
import type * as TC from "./type_classes.ts";
import { createDo } from "./derivations.ts";
import { createSequenceStruct, createSequenceTuple } from "./sequence.ts";
/*******************************************************************************
* Kind Registration
******************************************************************************/
@baetheus
baetheus / stream.ts
Last active August 30, 2021 17:56
Streams based on callbags
import type * as HKT from "./hkt.ts";
import type * as TC from "./type_classes.ts";
import type { Option } from "./option.ts";
import * as O from "./option.ts";
import { Queue } from "./denque.ts";
import { pipe } from "./fns.ts";
/*******************************************************************************
* Types
@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]>;