Skip to content

Instantly share code, notes, and snippets.

@abiodun0
Last active June 3, 2017 16:24
Show Gist options
  • Select an option

  • Save abiodun0/60ac9bf66523d6ba4be1d6aa67b82d7f to your computer and use it in GitHub Desktop.

Select an option

Save abiodun0/60ac9bf66523d6ba4be1d6aa67b82d7f to your computer and use it in GitHub Desktop.
unfold
const unfold = (f, seed) => {
const go = (f, seed, acc) => {
const res = f(seed);
return res ? go(f, res[1], acc.concat([res[0]])) : acc
}
return go(f, seed, []);
}
unfold(x => x < 26 ? [String.fromCharCode(x+65), x + 1] : undefined, 0) // Alphabets in capital letter
const range = (begin, end) => {
return unfold(x => x <= end ? [x, x+1]: undefined, begin)
}
range(67, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment