Skip to content

Instantly share code, notes, and snippets.

@sergey-shandar
Created June 5, 2025 18:27
Show Gist options
  • Select an option

  • Save sergey-shandar/c252d01dda3c04f1bc28d671597a329f to your computer and use it in GitHub Desktop.

Select an option

Save sergey-shandar/c252d01dda3c04f1bc28d671597a329f to your computer and use it in GitHub Desktop.
export const values
: <T>(a: readonly T[]) => Iterable<T>
= a => ({ *[Symbol.iterator]() { yield *a } })
const unitTest = () => {
// const it = [1, 2, 3] |> values //< F# style pipe
// const it = [1, 2, 3] |> values(%) //< Hack style pipe
const x = values([1, 2, 3])
const result = Array.from(x)
const r = JSON.stringify(result)
if (r !== JSON.stringify([1, 2, 3])) {
throw new Error(`Expected [1, 2, 3], but got ${r}`)
}
}
unitTest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment