Skip to content

Instantly share code, notes, and snippets.

View isthatcentered's full-sized avatar

Edouard isthatcentered

  • Lille, remote
View GitHub Profile
// Note, this is a (very) quick POC, this is far from perfect and needs improvement. But it works
import { pipe, identity } from "@effect/data/Function"
import * as T from "@effect/io/Effect"
import { TaggedClass } from "@effect/data/Data"
import * as Match from "@effect/match"
export class Given<R, S, A> extends TaggedClass("Given")<{
fa: T.Effect<R, any, S>
_A: (a: never) => A
@isthatcentered
isthatcentered / Disk.ts
Last active January 23, 2023 13:29
Typescript Free Monad
import { Tagged } from "@effect-ts/core/Case"
import * as P from "../../prelude"
import * as Free from "./FreeMonad"
import { makeFree } from "./FreeMonad"
import { identity, pipe } from "@effect-ts/core/Function"
import * as T from "@effect-ts/core/Effect"
import { matchTag } from "@effect-ts/core/Utils"
import * as FS from "fs"
import * as Ei from "@effect-ts/core/Either"
@isthatcentered
isthatcentered / Cause.ts
Created October 27, 2022 07:39
Typescript Task/Enhanced promise
class ExpectedError<E> {
readonly _tag = 'ExpectedError';
constructor(public readonly error: E) {}
}
class Die {
readonly _tag = 'Die';
constructor(public readonly reason: string, public readonly data: any) {}
}
describe(`Queue`, () => {
describe(`isEmpty`, () => {
test(`Empty queue returns true`, async () => {
const queue = new InMemoryQueue<string>();
const result = await queue.isEmpty();
expect(result).toEqual(true);
});
@isthatcentered
isthatcentered / matchTag.ts
Last active October 24, 2022 12:34
Typescript match discriminated union tag
type MatchTag = {
// Strict match, one handler must be provided for each possible tag
<
X extends { _tag: string },
K extends {
[k in X['_tag']]: (member: Extract<X, { _tag: k }>) => any
},
>(
handlers: K,
): (member: X) => ReturnType<K[keyof K]>
@isthatcentered
isthatcentered / fp.md
Last active January 7, 2021 03:25
Functional Programming cheat sheet

Partial vs Total

  • domain/codomain
  • deterministic

Referential transparency

def blah1() = if(false) throw new Exception else 2 

def blah2() = {
  val a = throw new Exception
 if(false) a else 2
@isthatcentered
isthatcentered / kill.txt
Last active June 29, 2019 05:26
Processes
ps -ax # List all running processes
ps -ax | grep {X} # Get all processes with name {X} Ex: ps -ax | grep Skype
kill {pid} # Kill a running process. Ex: kill 44345
# Kill a port
kill -2 $(lsof -t -i:4200) # https://stackoverflow.com/questions/39091735/port-4200-is-already-in-use-when-running-the-ng-serve-command
@isthatcentered
isthatcentered / demo.ts
Last active March 16, 2019 08:38
Javascript ES6 proxy object that never fails
import { Yolo } from "./yolo"
import { Loggable } from "./loggable"
// Nothing in this object ? Don't care, yolo
const x = Yolo<any>().whatever.i.wont.fail.lolz().im.batman()
// I know it's boring but If the value exist you can still access it ;)
const Y = Yolo<any>( { hello: { name: "world" } } ).hello.name // -> "world"
// Also, yay typescript
@isthatcentered
isthatcentered / commands.txt
Last active June 19, 2019 09:03
React - Testing setup
yarn add testdouble @testing-library/react jest-dom testdouble-jest jest-then enzyme enzyme-adapter-react-16 @types/enzyme @types/enzyme-adapter-react-16 -D
@isthatcentered
isthatcentered / DeepPartial.ts
Last active June 19, 2020 05:26
Typescript - Deep Partial
https://stackoverflow.com/questions/45372227/how-to-implement-typescript-deep-partial-mapped-type-not-breaking-array-properti/49936686#49936686
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U>
? Array<DeepPartial<U>>
: T[P] extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: DeepPartial<T[P]>
};