help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] #flatten for seq-collections, #join: for collection


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] #flatten for seq-collections, #join: for collection classes
Date: Wed, 06 Jun 2007 07:03:57 +0200
User-agent: Thunderbird 2.0.0.0 (Macintosh/20070326)


Because of the convenience of {}-syntax, flatten is also useful as a
more efficient concatenation operator than #','.  In fact, this is what
I intended it for.

Very cool! However, what about just calling #join also the instance-side #flatten, and omitting the instance-side #flatten: (which is simpler to do with a class-side #join:)?

#flatten is more for something like

  #((1 2) 3 (4 5)) => 1 2 3 4 5

This can be done by adding a #flattenInto: method that does "add: self" or "self do: [ :each | each flattenInto: dest ]" (the latter for collections and streams).

As a nitpick, #inject:into: is slow -- streams might be faster -- and #fold: is nicer anyway for the size computation.

And after Lisp, Smalltalk mimics APL too! :-P

Thanks,

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]