Object.st
changeset 22011 4feefa83e27c
parent 22008 fa021caa35e0
child 22025 5178bff40e4d
--- a/Object.st	Thu Jul 13 19:03:56 2017 +0200
+++ b/Object.st	Thu Jul 13 19:04:08 2017 +0200
@@ -257,7 +257,6 @@
     "Modified: / 4.8.1999 / 08:54:06 / stefan"
 ! !
 
-
 !Object class methodsFor:'Compatibility-ST80'!
 
 rootError
@@ -496,7 +495,6 @@
     InfoPrinting := aBoolean
 ! !
 
-
 !Object class methodsFor:'queries'!
 
 isAbstract
@@ -520,9 +518,6 @@
 
 
 
-
-
-
 !Object methodsFor:'Compatibility-GNU'!
 
 display
@@ -623,7 +618,6 @@
     self errorKeyNotFound:aKey.
 ! !
 
-
 !Object methodsFor:'accessing'!
 
 _at:index
@@ -1720,8 +1714,6 @@
     "
 ! !
 
-
-
 !Object methodsFor:'attributes access'!
 
 objectAttributeAt:attributeKey
@@ -1865,8 +1857,6 @@
 ! !
 
 
-
-
 !Object methodsFor:'change & update'!
 
 broadcast:aSelectorSymbol
@@ -2047,7 +2037,6 @@
     ^ aBlock ensure:[ self addDependent:someone ]
 ! !
 
-
 !Object methodsFor:'comparing'!
 
 = anObject
@@ -8140,7 +8129,6 @@
     ^ self
 ! !
 
-
 !Object methodsFor:'secure message sending'!
 
 ?:selector
@@ -8733,6 +8721,71 @@
     "
 ! !
 
+!Object methodsFor:'splitting & joining'!
+
+split:aSequenceableCollection
+    "treating the receiver as a splitter,
+     split aSequenceableCollection accordingly and return a collection of fragments."
+
+    | result |
+
+    result := OrderedCollection new:(aSequenceableCollection size // 2).
+    self split:aSequenceableCollection do:[:item |
+        result add:item
+    ].
+    ^ result
+
+    "
+     ' ' split: 'hello world'
+    "
+
+    "Created: / 13-07-2017 / 17:23:55 / cg"
+!
+
+split:aCollection do:aBlock
+    "treating the receiver as a splitter,
+     split aSequenceableCollection accordingly and evaluate aBlock for each fragment."
+
+    self split:aCollection indicesDo:[:start :stop |
+        aBlock value:(aCollection copyFrom:start to:stop)
+    ].
+
+    "
+     ' ' split: 'hello world' do: [:frag | Transcript showCR:frag ]
+    "
+
+    "Created: / 13-07-2017 / 16:43:28 / cg"
+    "Modified (comment): / 13-07-2017 / 18:11:53 / cg"
+!
+
+split:aCollection indicesDo:aTwoArgBlock
+    "treating the receiver as a splitter,
+     split aSequenceableCollection accordingly and evaluate aBlock for each pair of start-
+     and stop index."
+
+    |position oldPosition|
+
+    position := 1.
+    oldPosition := position.
+    position := aCollection indexOf:self startingAt:position.
+    [position > 0] whileTrue:[
+        aTwoArgBlock value:oldPosition value:position-1.
+        position := position + 1.
+        oldPosition := position.
+        position := aCollection indexOf:self startingAt:position.        
+    ].
+    aTwoArgBlock value:oldPosition value:aCollection size
+
+    "
+     1 split:#(10 1 20 30 40 1 50 60 1 70) do: [:frag | Transcript showCR:frag ]
+     1 split:#(10 1 20 30 40 1 50 60 1 70) indicesDo: [:start :stop | Transcript show:start; show:' to '; showCR:stop ]
+ 
+     nil split:#(10 nil 20 30 40 nil 50 60 nil 70) do: [:frag | Transcript showCR:frag ]
+     nil split:#(10 nil 20 30 40 nil 50 60 nil 70) indicesDo: [:start :stop | Transcript show:start; show:' to '; showCR:stop ]
+    "
+
+    "Created: / 13-07-2017 / 18:12:34 / cg"
+! !
 
 !Object methodsFor:'synchronized evaluation'!
 
@@ -10553,9 +10606,6 @@
     ^ aVisitor visitObject:self with:aParameter
 ! !
 
-
-
-
 !Object class methodsFor:'documentation'!
 
 version