OrderedSet.st
changeset 23135 752c53e34c53
parent 22424 06582f583ee4
child 23190 611aa626a4a4
--- a/OrderedSet.st	Tue Jun 26 21:00:37 2018 +0200
+++ b/OrderedSet.st	Wed Jun 27 08:10:51 2018 +0200
@@ -280,6 +280,36 @@
     ^ self remove:element.
 !
 
+removeIdentical:oldObject ifAbsent:exceptionValueProvider
+    "remove oldObject from the collection and return it.
+     If it was not in the collection return the value of exceptionValueProvider.
+
+     WARNING: do not remove elements while iterating over the receiver."
+
+    |removedObject|
+
+    removedObject := super removeIdentical:oldObject 
+                           ifAbsent:[ ^ exceptionValueProvider value].      
+    order removeIdentical:removedObject.
+
+    ^ removedObject
+
+    "
+     |s ef er|
+
+     s := OrderedSet new. 
+     s add:'abc'.
+     s add:'def'.
+     s add:'ghi'.
+     ef := s detect:[:el | el = 'def'].
+     er := s removeIdentical:ef.
+     s addFirst:er.
+     s
+    "
+
+    "Created: / 27-06-2018 / 08:08:28 / Claus Gittinger"
+!
+
 removeLast
     "remove the last object from the collection and return it.
      If it was not in the collection, raise an error.