awwx.ws

span0

http://awwx.ws/span0.arc:

(def span (tst lst)
  ((afn (a lst)
     (if (and lst (tst (car lst)))
          (self (cons (car lst) a) (cdr lst))
          (list (rev a) lst)))
   nil lst))

span splits a list into two lists: the first list is the longest prefix of the input list for which each element passes the test, and the second list is the rest of the list.

arc> (span even '(4 6 8 1 3 4 7 8))
((4 6 8) (1 3 4 7 8))

Get this hack

Using the hackinator:

$ hack \
    ycombinator.com/arc/arc3.1.tar \
    awwx.ws/span0.arc

unLicense

This code is in the public domain.

Contact me

Twitter: awwx
Email: andrew.wilcox [at] gmail.com