Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created January 23, 2021 21:47
Show Gist options
  • Save AndrewRayCode/44fd5cb1868266db33225566ca48d229 to your computer and use it in GitHub Desktop.
Save AndrewRayCode/44fd5cb1868266db33225566ca48d229 to your computer and use it in GitHub Desktop.
const foldrLazy = (fn, initialValue, [element, ...rest]) => {
if (element === undefined) {
return initialValue;
}
const exists = () => foldrShortCircuit(fn, initialValue, rest);
return fn(element, exists);
};
const someLazy = (fn, arr) =>
foldrLazy(
(value, accumulated) => fn(value) || accumulated(),
false,
arr
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment