Skip to content

Instantly share code, notes, and snippets.

@mitaki28
mitaki28 / lens.ts
Created November 5, 2016 17:51
Type-safe Lens (TypeScript 2.1)
// requires TypeScript 2.1 or higher
export abstract class Lens<T, U> {
abstract get: (obj: T) => U;
abstract set: (value: U) => (obj: T) => T;
then = <V>(lens: Lens<U, V>) => new ComposedLens(this, lens);
thenKey = <L extends keyof U>(key: L): Lens<T, U[L]> => this.then(new ObjectLens<U, L>(key));
modify = (f: (value: U) => U) => (obj: T) => this.set(f(this.get(obj)))(obj);
}
export class IdLens<T> extends Lens<T, T> {
@tkawachi
tkawachi / Code.class.base64
Last active August 29, 2015 14:16
Hello World! golf
yv66vgADAC0AEwwAEAASAQAWKFtMamF2YS9sYW5nL1N0cmluZzspVgEADEhlbGxvIFdvcmxkIQcACwgAAwcADgEABENvZGUBAARtYWluCQAGAAEMAAwAEQEAE2phdmEvaW8vUHJpbnRTdHJlYW0BAAdwcmludGxuBwAHAQAQamF2YS9sYW5nL1N5c3RlbQoABAAKAQADb3V0AQAVKExqYXZhL2xhbmcvU3RyaW5nOylWAQAVTGphdmEvaW8vUHJpbnRTdHJlYW07ACEADQAEAAAAAAABAAkACAACAAEABwAAABUAAgABAAAACbIACRIFtgAPsQAAAAAAAA==
@hexx
hexx / gist:5734520
Last active December 18, 2015 05:39
:- module ml.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is cc_multi.
:- implementation.
:- import_module bool, int, string, list, pair, assoc_list, lex, regex.
main(!IO) :-
Lexer = lex.init(lexemes, lex.read_from_stdin, ignore(space)),
State0 = lex.start(Lexer, !.IO),