Skip to content

Instantly share code, notes, and snippets.

@christianvdstap
Created September 29, 2021 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianvdstap/2d5502252c7180d615bec65d6e918066 to your computer and use it in GitHub Desktop.
Save christianvdstap/2d5502252c7180d615bec65d6e918066 to your computer and use it in GitHub Desktop.
Infinite loop
function tail(v) =
let(n=len(v))
n > 0
? [for (i=[1:n-1]) v[i]]
: []
;
function head(v) =
let(n=len(v))
n > 0
? [v[0]]
: []
;
function filter(v, predicate=function(x) true, acc=[]) =
let(n=len(v))
n > 0
? filter(tail(v), predicate, predicate(v[0]) ? concat(acc, head(v)) : acc)
: acc
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment