Skip to content

Instantly share code, notes, and snippets.

@drew-y
Created February 28, 2019 00:15
Show Gist options
  • Save drew-y/76f1689a397f69efea39911df377e645 to your computer and use it in GitHub Desktop.
Save drew-y/76f1689a397f69efea39911df377e645 to your computer and use it in GitHub Desktop.
Simple TypeScript Pipe Pattern Implementation
interface Pipe<T> {
val: T;
into<U>(cb: (val: T) => U): Pipe<U>;
}
function pipe<T>(val: T): Pipe<T> {
return { val, into: cb => pipe(cb(val)) }
}
// // Example Usage
// export const inverseEuler = (e: Euler) => pipe(e)
// .into(eulerToQuaternion)
// .into(inverseQuaternion)
// .into(quaternionToEuler)
// .val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment