chickadee » srfi-1 » break!

span pred clistprocedure
span! pred listprocedure
break pred clistprocedure
break! pred listprocedure

Span splits the list into the longest initial prefix whose elements all satisfy PRED, and the remaining tail. Break inverts the sense of the predicate: the tail commences with the first element of the input list that satisfies the predicate.

In other words: span finds the intial span of elements satisfying PRED, and break breaks the list at the first element satisfying PRED.

Span is equivalent to

(values (take-while PRED CLIST) 
        (drop-while PRED CLIST))

Span! and break! are the linear-update variants. They are allowed, but not required, to alter the argument list to produce the result.

(span even? '(2 18 3 10 22 9)) =>
  (2 18)
  (3 10 22 9)
 
(break even? '(3 1 4 1 5 9)) =>
  (3 1)
  (4 1 5 9)