Smalltalk
Date: 08/02/05
(Code WTF) Keywords: no keywords
Collection >> do: operation separatedBy: separator
"Evaluate the argument, operation,
for each of the receiver's elements, interspersed
with evaluations of the
argument, separator. The separator is first
evaluated after the first element, and is not
evaluated after the last element (i.e. it is not
evaluated at all if there are less than two elements)."
| sep |
"Switch to the real separator after first eval."
sep := [sep := separator].
self do: [:e |
sep value.
operation value: e].
sep := nil.
Source: http://www.livejournal.com/community/code_wtf/12990.html