SequenceableCollection.st
changeset 25286 25a8dda1990b
parent 25229 ffb4208adfe8
child 25344 b6b71d974e50
--- a/SequenceableCollection.st	Sun Feb 23 14:21:06 2020 +0100
+++ b/SequenceableCollection.st	Sun Feb 23 15:45:01 2020 +0100
@@ -3311,6 +3311,25 @@
     "
 !
 
+copyButFirstAndLast
+    "return a new collection consisting of the receiver's elements
+     except for the first and last elements.
+     Raises an error if the receiver's size is less than 2."
+
+    |sz|
+
+    (sz := self size) < 2 ifTrue:[self notEnoughElementsError].
+    ^ self copyFrom:2 to:(sz - 1)
+
+    "
+     #($a $b $c $d $e $f $g) copyButFirstAndLast
+     '1234567890' copyButFirstAndLast
+     '1' copyButFirstAndLast
+     '' copyButFirstAndLast
+     'ab' copyButFirstAndLast
+    "
+!
+
 copyButLast
     "return a new collection consisting of the receiver's elements
      except for the last element.