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 * as T from "monocle-ts/lib/Traversal"; | |
import * as R from "fp-ts/lib/Record"; | |
import { pipe } from "fp-ts/lib/function"; | |
import { Lens } from "monocle-ts"; | |
type Person = { | |
age: number; | |
hairColor: string; | |
}; |
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
//Source: https://functionalprogramming.slack.com/archives/C7BBY9A95/p1594724501330700?thread_ts=1594687497.326100&cid=C7BBY9A95 | |
type UnionToIntersection<U> = | |
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; |
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
function refProxy<T>( | |
ref: React.MutableRefObject<T> | |
): React.MutableRefObject<T> & { current: O.Option<T> } { | |
const p = new Proxy( | |
ref as React.MutableRefObject<T> & { current: O.Option<T> }, | |
{ | |
get: (target, prop) => { | |
if (prop === "current") { | |
return O.fromNullable(target.current); |
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
interface CurriedFn2<A, B, R> { | |
<A>(a: A): CurriedFn1<B, R> | |
<A, B>(a: A, b: B): R | |
} |
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 {Applicative1} from 'fp-ts/lib/Applicative'; | |
import * as Array from 'fp-ts/lib/Array'; | |
import {Kind, URIS} from 'fp-ts/lib/HKT'; | |
import {pipe} from 'fp-ts/lib/pipeable'; | |
export type HKD<F extends URIS, A> = {[K in keyof A]: Kind<F, A[K]>}; | |
export const sequenceHKD = <F extends URIS>(F: Applicative1<F>) => <A>( | |
lifted: HKD<F, A>, | |
): Kind<F, 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
import { array } from 'fp-ts/lib/Array'; | |
import { flow, tuple } from 'fp-ts/lib/function'; | |
import * as Option from 'fp-ts/lib/Option'; | |
export const composedPath = (e: MouseEvent) => { | |
if (e['composedPath']) { | |
return e.composedPath(); | |
} | |
if (e.target instanceof HTMLElement) { |
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 * as A from "fp-ts/lib/Array"; | |
import * as M from "fp-ts/lib/Map"; | |
import { eqNumber } from "fp-ts/lib/Eq"; | |
//My domain type | |
type User = { | |
name: string; | |
age: number; | |
}; |
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 const getMagmaRight = <A>(): Magma<A> => ({ | |
concat: (a, b) => b | |
}); |
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
const assertOption = <A>(op: Option.Option<A>): A => { | |
if(Option.isNone(op)) { | |
throw new Error("assertSome failed.") | |
} | |
return op.value; | |
} |
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 const invert = <A,B,C>(ordA: Ord<A>, ordB:Ord<B>) => (map:Map<A,Map<B,C>>): Map<B,Map<A,C>> => { | |
const arrayABC = pipe( | |
map, | |
M.toArray(ordA), | |
Array.map(([a, mapBC]) => pipe( | |
mapBC, | |
M.toArray(ordB), | |
Array.map(([b,c]) => [a,b,c] as const) | |
)), | |
Array.flatten |