Created
February 28, 2019 00:15
-
-
Save drew-y/76f1689a397f69efea39911df377e645 to your computer and use it in GitHub Desktop.
Simple TypeScript Pipe Pattern Implementation
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 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