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 MyState = { | |
store1: {foo: number}, | |
store2: {bar: number} | |
}; | |
const initialState: MyState = { | |
store1: {foo: 0}, | |
store2: {bar: 0}, | |
} |
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 Ord from 'fp-ts/lib/Ord'; | |
import * as Eq from 'fp-ts/lib/Eq'; | |
import {pipe} from 'fp-ts/lib/pipeable'; | |
import * as Array from 'fp-ts/lib/Array'; | |
import * as NonEmptyArray from 'fp-ts/lib/NonEmptyArray'; | |
export type Priority<A> = { | |
priority: number; | |
value: 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 { Lens } from 'monocle-ts' | |
type Foo = { | |
bar?: { | |
baz?: number[] | |
} | |
} | |
const bar = Lens.fromNullableProp<Foo>()('bar', {}) | |
const baz = Lens.fromNullableProp<Foo['bar']>()("baz", []) |
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 { Optional } from "monocle-ts"; | |
import * as Option from "fp-ts/lib/Option"; | |
type Baz2 = number; | |
type Bar2 = { | |
baz: Option.Option<Baz2>; | |
}; | |
type Foo2 = { | |
bar: Option.Option<Bar2>; | |
}; |
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 React from "react" | |
type Level = "read" | "read_write" | |
type Restricted<A, B> = (l: Level) => (a: A) => B | |
function restricted<A, B>(required: Level, whenAuth: (a: A) => B, whenNotAuth: () => B) { | |
return (level: Level) => (a: A) => required === level | |
? whenAuth(a) | |
: whenNotAuth(); | |
} |
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 Option from "fp-ts/lib/Option"; | |
import { pipe } from "fp-ts/lib/pipeable"; | |
type Permission = "read" | "read_write"; | |
interface Restricted<A, B> { | |
(l: Permission): (a: A) => Option.Option<B>; | |
} | |
//so instead of having the whenNotAuthed, that only is given upon "run" along with level |
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/Applicative"; | |
import { URIS, Kind } from "fp-ts/lib/HKT"; | |
import { Option, option, some } from "fp-ts/lib/Option"; | |
const lift = <F extends URIS, A, B, C>( | |
F: A.Applicative1<F>, | |
fn: (a: A) => (b: B) => C | |
) => (fa: Kind<F, A>) => (fb: Kind<F, B>): Kind<F, C> => { | |
const fab = F.map(fa, fn); | |
const c = F.ap(fab, fb); |
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 Control.Comonad | |
data Stream a = a :> Stream a | |
instance Functor Stream where | |
fmap f (a :> rest) = f a :> (fmap f rest) |
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 flip<Args1 extends any[], Args2 extends any[], R>( | |
fn: (...args1: Args1) => (...args2: Args2) => R | |
) { | |
return (...args2: Args2) => (...args1: Args1) => fn(...args1)(...args2); | |
} | |
function uncurry<A, Args2 extends any[], R>( | |
fn: (arg: A) => (...args2: Args2) => 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
ghcid "--command=stack ghci --ghci-options -i src/Main.hs" | |
//https://github.com/dramforever/vscode-ghc-simple |