The Inbox: Collections-mt.848.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-mt.848.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.848.mcz

==================== Summary ====================

Name: Collections-mt.848
Author: mt
Time: 14 August 2019, 3:51:55.072512 pm
UUID: 374f81b1-f8c1-1a49-9078-ce11ed34de8b
Ancestors: Collections-fn.847

Resolve the discussion about Collections-ct.827 (http://forum.world.st/The-Inbox-Collections-ct-827-mcz-td5099876.html) to move or not to move #joinSeparatedBy:.

1) Do not move it.
2) Document the decision in #joinSeparatedBy:.
3) Prepare similar "print-on-delimiter" on Collection for deprecation.
4) Add #joinOn: ... similar to #printElemetsOn:.

So, there is still that #printElementsOn: working on all kinds of Collection.

=============== Diff against Collections-fn.847 ===============

Item was changed:
+ ----- Method: Collection>>asCommaString (in category 'printing - obsolete') -----
- ----- Method: Collection>>asCommaString (in category 'printing') -----
  asCommaString
  "Return collection printed as 'a, b, c' "
 
+ self flag: #deprecate.
+ ^ self asArray joinSeparatedBy: ', '
- ^String streamContents: [:s | self asStringOn: s delimiter: ', ']
  !

Item was changed:
+ ----- Method: Collection>>asCommaStringAnd (in category 'printing - obsolete') -----
- ----- Method: Collection>>asCommaStringAnd (in category 'printing') -----
  asCommaStringAnd
  "Return collection printed as 'a, b and c' "
 
+ self flag: #deprecate.
  ^String streamContents: [:s | self asStringOn: s delimiter: ', ' last: ' and ']
  !

Item was changed:
+ ----- Method: Collection>>asStringOn:delimiter: (in category 'printing - obsolete') -----
- ----- Method: Collection>>asStringOn:delimiter: (in category 'printing') -----
  asStringOn: aStream delimiter: delimString
- "Print elements on a stream separated
- with a delimiter String like: 'a, b, c'
- Uses #asString instead of #print:."
 
+ self flag: #deprecate.
+ ^ self asArray joinSeparatedBy: delimString!
- self do: [:elem | aStream nextPutAll: elem asString]
- separatedBy: [aStream nextPutAll: delimString]!

Item was changed:
+ ----- Method: Collection>>asStringOn:delimiter:last: (in category 'printing - obsolete') -----
- ----- Method: Collection>>asStringOn:delimiter:last: (in category 'printing') -----
  asStringOn: aStream delimiter: delimString last: lastDelimString
  "Print elements on a stream separated
  with a delimiter between all the elements and with
  a special one before the last like: 'a, b and c'.
  Uses #asString instead of #print:
 
  Note: Feel free to improve the code to detect the last element."
 
  | n sz |
+ self flag: #deprecate.
+
  n := 1.
  sz := self size.
  self do: [:elem |
  n := n + 1.
  aStream nextPutAll: elem asString]
  separatedBy: [
  aStream nextPutAll: (n = sz ifTrue: [lastDelimString] ifFalse: [delimString])]!

Item was changed:
  ----- Method: Collection>>printElementsOn: (in category 'printing') -----
  printElementsOn: aStream
- "The original code used #skip:, but some streams do not support that,
- and we don't really need it."
 
+ self
+ printElementsOn: aStream
+ separatedBy: String space.!
- aStream nextPut: $(.
- self do: [:element | aStream print: element] separatedBy: [aStream space].
- aStream nextPut: $)!

Item was added:
+ ----- Method: Collection>>printElementsOn:separatedBy: (in category 'printing') -----
+ printElementsOn: aStream separatedBy: delimiter
+ "Do not use #print: on the delemiter to have more control over the output. Strings get quoted, Characters get prefixed, etc."
+
+ self
+ do: [:element | aStream print: element]
+ separatedBy: [aStream nextPutAll: delimiter asString].!

Item was changed:
  ----- Method: Collection>>printOn: (in category 'printing') -----
  printOn: aStream
  "Append a sequence of characters that identify the receiver to aStream."
 
  self printNameOn: aStream.
+
+ aStream nextPut: $(.
+ self printElementsOn: aStream.
+ aStream nextPut: $).
+ !
- self printElementsOn: aStream!

Item was changed:
+ ----- Method: Collection>>printOn:delimiter: (in category 'printing - obsolete') -----
- ----- Method: Collection>>printOn:delimiter: (in category 'printing') -----
  printOn: aStream delimiter: delimString
- "Print elements on a stream separated
- with a delimiter String like: 'a, b, c' "
 
+ self flag: #deprecate.
+ self
+ printElementsOn: aStream
+ separatedBy: delimString.!
- self do: [:elem | aStream print: elem] separatedBy: [aStream print: delimString]
- !

Item was changed:
+ ----- Method: Collection>>printOn:delimiter:last: (in category 'printing - obsolete') -----
- ----- Method: Collection>>printOn:delimiter:last: (in category 'printing') -----
  printOn: aStream delimiter: delimString last: lastDelimString
  "Print elements on a stream separated
  with a delimiter between all the elements and with
  a special one before the last like: 'a, b and c'
 
  Note: Feel free to improve the code to detect the last element."
 
  | n sz |
+ self flag: #deprecate.
  n := 1.
  sz := self size.
  self do: [:elem |
  n := n + 1.
  aStream print: elem]
  separatedBy: [
  n = sz
  ifTrue: [aStream print: lastDelimString]
  ifFalse: [aStream print: delimString]]!

Item was added:
+ ----- Method: SequenceableCollection>>joinOn: (in category 'printing') -----
+ joinOn: stream
+
+ ^ self joinOn: stream separatedBy: ''!

Item was added:
+ ----- Method: SequenceableCollection>>joinOn:separatedBy: (in category 'printing') -----
+ joinOn: stream separatedBy: aSeparator
+
+ self
+ do: [:ea | stream nextPutAll: ea asString]
+ separatedBy: [stream nextPutAll: aSeparator asString].!

Item was changed:
  ----- Method: SequenceableCollection>>joinSeparatedBy: (in category 'converting') -----
  joinSeparatedBy: aSeparator
+ "Returns a string, which is a concatenation of each element's string representation separated by another string.
+
+ August 2019 -- http://forum.world.st/The-Inbox-Collections-ct-827-mcz-td5099876.html
+ There was a discussion about whether to move this method up to Collection. We identified a trade-off between (iinterface) convenience and (result) predictability. In Collection, this method would be available for Set, too. However, random result order makes such a feature questionable. What would be the result of #(1 2 3) asSet joinSeparatedBy: '-'? For such scenarios, some people argued, it would be better to explicitely call #asArray and maybe explain why a non-sequenceable collection was used in the first place."
- "Returns a string, which is a concatenation of each element's string representation separated by another string."
 
  ^ String streamContents: [:stream |
+ self joinOn: stream separatedBy: aSeparator]!
- self
- do: [:ea | stream nextPutAll: ea asString]
- separatedBy: [stream nextPutAll: aSeparator asString]]!