#FEATURE by cg
authorClaus Gittinger <cg@exept.de>
Wed, 03 Apr 2019 12:41:40 +0200
changeset 4934 91b2585d2cba
parent 4933 f6c830dda3b0
child 4935 2044cf9f3790
#FEATURE by cg class: List added: #dropLast: similar to removeLast:, but does not return the removed elements.
List.st
--- a/List.st	Wed Apr 03 08:37:30 2019 +0200
+++ b/List.st	Wed Apr 03 12:41:40 2019 +0200
@@ -245,6 +245,23 @@
     "Modified (format): / 01-08-2018 / 11:51:29 / Claus Gittinger"
 !
 
+dropLast:n
+    "remove the last n elements from the receiver collection. 
+     Return the receiver."
+
+    self possiblySynchronized:[
+        | stop |
+        stop := self size.
+        super dropLast:n.
+        dependents notNil ifTrue:[
+            self changed:#removeFrom: with:(Array with:(stop - n + 1) with:stop).
+        ].
+    ].
+    ^ self
+
+    "Created: / 03-04-2019 / 12:40:35 / Claus Gittinger"
+!
+
 removeAll
     "remove all elements from the collection.
      Returns the receiver."