Skip to content

Instantly share code, notes, and snippets.

View colorincode's full-sized avatar

Kayla B colorincode

  • Color in code
View GitHub Profile
@colorincode
colorincode / tramp.ts
Created July 11, 2024 18:57 — forked from trvswgnr/tramp.ts
trampoline typescript
/**
* Transforms a function that returns either a direct value or a thunk (a
* no-argument function that returns a value) into a function that only returns
* a direct value. It does this by repeatedly evaluating the function if it
* returns a thunk, until a direct value is obtained.
*
* @template T The type of the value to be returned by the trampoline function.
* @template A The type tuple representing the argument types accepted by the
* function `f`.
* @param f A function that takes arguments of type `A` and returns either a