This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type MapTo<T extends Record<string, V>, K extends keyof V, V> = { | |
[K2 in keyof T]: T[K2][K] | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert record to union of its members | |
// eg {foo: string, bar: number} -> {key: 'foo', value: string} | {key: 'bar' value: number}; | |
type RecordUnion<T extends Record<string, any>> = { | |
[K in keyof T]: { key: K, value: T[K] } | |
}[keyof T]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>> | |
type OptionalKeys<T> = Exclude<{ | |
[K in keyof T]: Extract<T[K], undefined> extends never ? never : K; | |
}[keyof T], undefined>; | |
type UndefinedToUnrequired<T> = { | |
[K in OptionalKeys<T>]?: T[K] | |
} & Omit<T, OptionalKeys<T>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Either, left, right } from "fp-ts/lib/Either"; | |
import { Task, task } from "fp-ts/lib/Task"; | |
type Env<R, E, A> = (r: R) => Task<Either<E, A>>; | |
const run = <R, E, A>(r: R, env: Env<R, E, A>) => env(r); | |
const of = <R, E, A>(a: A): Env<R, E, A> => | |
(r: R) => task.of(right(a)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pair = [number, number]; | |
type Entity = { | |
dimensions: Pair; | |
pos: Pair; | |
img: HTMLImageElement; | |
collider: number; | |
}; | |
type GameState = { | |
keyCode: number | null; | |
player: Entity; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Pair = [number, number]; | |
type GameState = { | |
keyCode: number | null; | |
playerPos: Pair; | |
playerImg: HTMLImageElement; | |
enemyPos: Pair; | |
enemyImg: HTMLImageElement; | |
}; | |
function game() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Prelude | |
import Effect (Effect) | |
import Effect.Console (log) | |
import Debug.Trace (trace) | |
import Math (pow, pi) | |
import Graphics.Canvas | |
import Partial.Unsafe (unsafePartial) | |
import Data.Maybe (Maybe(..)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* References | |
https://apfelmus.nfshost.com/articles/monoid-fingertree.html | |
https://abhiroop.github.io/Finger-Trees/ | |
https://chrispenner.ca/posts/intro-to-finger-trees | |
http://www.staff.city.ac.uk/~ross/papers/FingerTree.html | |
*/ | |
import { Monoid } from "fp-ts/lib/Monoid"; | |
import { Newtype, iso } from "newtype-ts"; | |
import { Predicate } from "fp-ts/lib/function"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type K = <A>(a: A) => <B>(b: B) => A; | |
type S = <A, B, C>(abc: (a: A) => (b: B) => C) => (ab: (a: A) => B) => (a: A) => C; | |
const K: K = a => b => a; | |
const S: S = abc => ab => a => abc(a)(ab(a)); | |
type IGNORED = "ignored"; | |
function IforallT<T>(t: T): (t: T) => T { | |
//To make I from S we need to achieve | |
//a :: T, b is ignored, c == a :: T | |
//if b is ignored then the ab arg of S becomes irrelevant, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { head as headArr, reverse, snoc as snocArr, tail as tailArr } from "fp-ts/lib/Array"; | |
import { | |
applyFlipped, | |
compose, | |
constant, | |
Curried2, | |
Curried3, | |
curry, | |
Endomorphism, | |
flip, |