Skip to content

Instantly share code, notes, and snippets.

@kelsny
kelsny / README.md
Last active February 13, 2022 16:31
CodeWars RoboScript Kata Solutions

These are my solutions to the RoboScript series of katas on CodeWars.

This Kata Series is based on a fictional story about a computer scientist and engineer who owns a firm that sells a toy robot called MyRobot which can interpret its own (esoteric) programming language called RoboScript. Naturally, this Kata Series deals with the software side of things (I'm afraid Codewars cannot test your ability to build a physical robot!).

@kelsny
kelsny / better-rxjs-pipe.ts
Created November 9, 2021 16:35
Extension of my previous gist specialized for RxJS
type UnaryFunction<T, R> = (source: T) => R;
type Identity = <T>(source: T) => T;
type Pipe<T, L = void, R extends UnaryFunction<any, any>[] = []> =
T extends []
? R
: L extends void
? T extends [(_: infer P) => infer V, ...infer Rest]
? Pipe<Rest, V, [...R, UnaryFunction<P, V>]>
@kelsny
kelsny / pipe.ts
Last active November 9, 2021 16:13
Arbitrary arity pipe function typings
type UnaryFunction<T, R> = (source: T) => R;
type Pipe<T, L = void, R extends UnaryFunction<any, any>[] = []> =
T extends []
? R
: L extends void
? T extends [(_: infer P) => infer V, ...infer Rest]
? Pipe<Rest, V, [...R, UnaryFunction<P, V>]>
: never[]
: T extends [(_: L) => infer V, ...infer Rest]