[squeak-dev] The Inbox: Collections-tfel.131.mcz
commits at source.squeak.org
commits at source.squeak.org
Mon Sep 14 12:00:32 UTC 2009
Tim Felgentreff uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-tfel.131.mcz
==================== Summary ====================
Name: Collections-tfel.131
Author: tfel
Time: 14 September 2009, 2:00:17 am
UUID: 61c6b5e1-32e7-4ae0-8934-d347b7fa2f29
Ancestors: Collections-tfel.130
As the previous, just fixing for OrderedCollection subclasses. Tried to make it shorter than it can be
=============== Diff against Collections-tfel.130 ===============
Item was changed:
----- Method: SequenceableCollection>>flatten (in category 'converting') -----
flatten
"Remove all nesting of myself from me (Strings are not flattened
though). E.g.: {3 .4 .{2 .4 .{'hi'} .'ho'}} flatten = {3 .4 .2 .4 .'hi' .'ho'}"
| flattened subFlattened index |
+ flattened := Array
- flattened := self species
new: (self inject: 0 into: [:subTotal :next |
(next isCollection and: [next isString not])
ifTrue: [subTotal + next flatten size]
ifFalse: [subTotal + 1]]).
index := 1.
self do: [:each |
(each isCollection and: [each isString not])
ifTrue: [
subFlattened := each flatten.
flattened
atAll: (index to: index + subFlattened size - 1)
putAll: subFlattened.
index := index + subFlattened size]
ifFalse: [
flattened at: index put: each.
index := index + 1]].
+ ^ self species newFrom: flattened!
- ^ flattened!
More information about the Squeak-dev
mailing list
|