From 04e28e979a0f395b82294c1ec41cefdeec571638 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Thu, 21 Feb 2019 03:49:31 +0000 Subject: [PATCH] extended Collection with asOrderedCollection --- moo/kernel/Collect.moo | 15 +++++++++++++++ moo/kernel/test-001.moo | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index b57218e..eb203f0 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -722,6 +722,7 @@ class OrderedCollection(SequenceableCollection) } *) } + ## ------------------------------------------------------------------------------- class Set(Collection) @@ -1543,3 +1544,17 @@ class LinkedList(Collection) ^Error.Code.ENOENT } } + +extend Collection +{ + ## =================================================================== + ## CONVERSION + ## =================================================================== + method asOrderedCollection + { + | coll | + coll := OrderedCollection new: self size. + self do: [:each | coll addLast: each ]. + ^coll + } +} diff --git a/moo/kernel/test-001.moo b/moo/kernel/test-001.moo index 99c4445..8687c98 100644 --- a/moo/kernel/test-001.moo +++ b/moo/kernel/test-001.moo @@ -250,7 +250,19 @@ extend MyObject [ (-9p10.123 scale) = (-10.123000000 scale) ], [ (+3p100.1 + 16rffff + +5p1.22 + -5p1.223) = 65635.09700 ], + ## 80-84 + [ (30p2123.12 asString) = '2123.120000000000000000000000000000' ], + [ (+30p2123.12 asString) = '2123.120000000000000000000000000000' ], + [ (-30p2123.12 asString) = '-2123.120000000000000000000000000000' ], + ## ========================= + [ + | k | + k := String new. + (%( 1 + 2, -21391239218392 * +291382913821, 19p10 div: 3 ) asOrderedCollection) doWithIndex: [:each :index | k := k & (index asString) & '=>' & (each asString) & ' '. ]. + k = '0=>3 1=>-6233041613697111534195832 2=>3.3333333333333333333 '. + ], + [ | b | b := [:n | (n > 0) ifTrue: [ n * (b value: n - 1)] ifFalse: [1]].