This file contains 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
/** | |
* Creates a range of alphabetical characters from | |
* start (inclusive) to stop (exclusive). | |
*/ | |
function range(start: string, stop: string): string[] { | |
var result: string[] = []; | |
var index: number; | |
for (var index = start.charCodeAt(0), end = stop.charCodeAt(0); index <= end; ++index){ | |
result.push(String.fromCharCode(index)); |
This file contains 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 MaybeUtils where | |
import Maybe exposing (Maybe(..)) | |
(<$>) : (a -> b) -> Maybe a -> Maybe b | |
(<$>) = Maybe.map | |
infixl 4 <$> | |
(<*>) : Maybe (a -> b) -> Maybe a -> Maybe b | |
(<*>) a m = |
This file contains 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 F1<A, Z> { | |
(_0: A): Z; | |
} | |
interface F2<A, B, Z> { | |
(_0: A, _1: B): Z; | |
(_0: A): F1<B, Z>; | |
} | |
interface F3<A, B, C, Z> { |
This file contains 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 returnType<A, B, Z>(fn: (a: A, b: B) => Z): Z | |
function returnType<A, Z>(fn: (a: A) => Z): Z | |
function returnType<Z>(fn: () => Z): Z | |
function returnType(): any { | |
throw "Nooooo" | |
} | |
function complicated(value: number): { kind: 'complicated', value: number } { | |
return { kind: 'complicated', value: value } | |
} |
This file contains 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 ClassAmendedWith<O extends object, C extends new (...args: any[]) => O, Properties extends object> = | |
C & (new (...args: any[]) => O & Properties) | |
class Henk { | |
constructor(public x: string, public y: number) { | |
} | |
} | |
const MyClass: ClassAmendedWith<Henk, typeof Henk, { z: boolean }> = null |
This file contains 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 Validated<E, A> = ValidatedOk<E, A> | ValidatedError<E, A> | |
type ErrorOfValidated<V extends Validated<any, any>> = V['errorType'] | |
type ValueOfValidated<V extends Validated<any, any>> = V['valueType'] | |
const Validated = { | |
ok<E, A>(a: A): ValidatedOk<E, A> { | |
return new ValidatedOk<E, A>(a) | |
}, |
This file contains 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 Monads<A> {} | |
type MonadToken = keyof Monads<any> | |
type Monad<F extends MonadToken, A> = { | |
_hkt: F | |
_a: A | |
flatMap<B>(fn: (a: A) => Monad<F, B>): Monads<B>[F] | |
} |
This file contains 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 Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T] | |
type Omit<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]} | |
const paramRegex = /:([^\/]+)/g | |
class UrlBuilder<Params> { | |
static fromUrl<Params>(url: string): UrlBuilder<Params> { | |
return new UrlBuilder<Params>(url, {}) | |
} |
This file contains 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 Path1<O, K extends keyof O> = [K] | |
type Path2<O, K1 extends keyof O, K2 extends keyof O[K1]> = [K1, K2] | |
const x = { | |
hamster: true, | |
food: { | |
hamster: 'hamsterfood', | |
human: 4 | |
} | |
} |
This file contains 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 Lazy<A> = () => A | |
function lazy<A>(fn: () => A): Lazy<A> { | |
type State | |
= { evaluated: false, evaluator: () => A } | |
| { evaluated: true, value: A } | |
let state: State = { evaluated: false, evaluator: fn } | |
return () => { | |
if (state.evaluated === true) { | |
return state.value |
OlderNewer