From 913f5f6918171cfe165e650ca07b3540ab5d3bbb Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Tue, 19 Jun 2018 17:13:20 +0000 Subject: [PATCH] added add: and addAll: to OrderedCollection --- moo/kernel/Collect.moo | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/moo/kernel/Collect.moo b/moo/kernel/Collect.moo index 7727981..356a9bb 100644 --- a/moo/kernel/Collect.moo +++ b/moo/kernel/Collect.moo @@ -35,17 +35,6 @@ class Collection(Object) ^self subclassResponsibility: #do } - method detect: block - { - self detect: block ifNone: [ ^self error: 'not found' ]. - } - - method detect: block ifNone: exception_block - { - self do: [ :el | if (block value: el) { ^el } ]. - ^exception_block value. - } - method collect: block { | coll | @@ -54,6 +43,18 @@ class Collection(Object) ^coll } + method detect: block + { + ^self detect: block ifNone: [ ^self error: 'not found' ]. + } + + method detect: block ifNone: exception_block + { + ## returns the first element for which the block evaluates to true. + self do: [ :el | if (block value: el) { ^el } ]. + ^exception_block value. + } + method select: condition_block { | coll | @@ -457,6 +458,17 @@ class OrderedCollection(SequenceableCollection) ^obj. } + method add: obj + { + ^self addLast: obj. + } + + method addAll: coll + { + coll do: [:el | self addLast: el ]. + ^coll. + } + method removeFirst { | obj |