2098 'abcde' startsWithAnyOf:#('AB' 'ab') |
2097 'abcde' startsWithAnyOf:#('AB' 'ab') |
2099 'abcde' startsWithAnyOf:#('AC' 'ac') |
2098 'abcde' startsWithAnyOf:#('AC' 'ac') |
2100 #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 4)) |
2099 #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 4)) |
2101 #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 2)) |
2100 #[1 2 3 4] startsWithAnyOf:#( #(1 3) #(1 2)) |
2102 " |
2101 " |
|
2102 ! |
|
2103 |
|
2104 with:aCollection findFirst:aBlock |
|
2105 "return the index of the first element for which aTwoArgBlock returns true |
|
2106 against corresponding elements of aCollection. |
|
2107 If any collection is smaller, the size of the smaller plus one is returned" |
|
2108 |
|
2109 |mySize otherSize minSize| |
|
2110 |
|
2111 mySize := self size. |
|
2112 otherSize := aCollection size. |
|
2113 minSize := mySize min:otherSize. |
|
2114 |
|
2115 self from:1 to:minSize with:aCollection doWithIndex:[:el1 :el2 :i | |
|
2116 (aBlock value:el1 value:el2) ifTrue:[ ^ i]. |
|
2117 ]. |
|
2118 |
|
2119 mySize ~= otherSize ifTrue:[ |
|
2120 ^ minSize + 1 |
|
2121 ]. |
|
2122 ^ 0 |
|
2123 |
|
2124 " |
|
2125 'hello' with:'helLo' findFirst:[:a :b | a ~= b] |
|
2126 'hello' with:'hello' findFirst:[:a :b | a ~= b] |
|
2127 'hello' with:'hello1' findFirst:[:a :b | a ~= b] |
|
2128 'hello1' with:'hello' findFirst:[:a :b | a ~= b] |
|
2129 " |
|
2130 |
|
2131 "Created: / 08-01-2012 / 17:12:00 / cg" |
2103 ! ! |
2132 ! ! |
2104 |
2133 |
2105 !SequenceableCollection methodsFor:'converting'! |
2134 !SequenceableCollection methodsFor:'converting'! |
2106 |
2135 |
2107 asCollectionOfSubCollectionsOfSize:pieceSize |
2136 asCollectionOfSubCollectionsOfSize:pieceSize |
4362 #(faba one two three four five six) |
4391 #(faba one two three four five six) |
4363 from:2 to:5 select:[:element | element startsWith:'f'] |
4392 from:2 to:5 select:[:element | element startsWith:'f'] |
4364 " |
4393 " |
4365 ! |
4394 ! |
4366 |
4395 |
|
4396 from:startArg to:stopArg with:aSequenceableCollection doWithIndex:aThreeArgBlock |
|
4397 "evaluate the argument, aBlock for successive elements from |
|
4398 each the receiver and the argument, aSequenceableCollection. |
|
4399 aBlock must be a three-argument block, which get elements from either collection and |
|
4400 the index as arguments. |
|
4401 The collection argument must implement access via a numeric key." |
|
4402 |
|
4403 |start "{ Class: SmallInteger }" |
|
4404 stop "{ Class: SmallInteger }" | |
|
4405 |
|
4406 start := startArg. |
|
4407 stop := stopArg. |
|
4408 start to:stop do:[:index | |
|
4409 aThreeArgBlock |
|
4410 value:(self at:index) |
|
4411 value:(aSequenceableCollection at:index) |
|
4412 value:index. |
|
4413 ] |
|
4414 |
|
4415 " |
|
4416 #(one two three four five six) |
|
4417 from:2 to:5 |
|
4418 with:(1 to:10) |
|
4419 doWithIndex:[:el1 :el2 :idx| Transcript show:idx; space; show:el1; space; showCR:el2] |
|
4420 " |
|
4421 |
|
4422 "Created: / 08-01-2012 / 17:18:34 / cg" |
|
4423 ! |
|
4424 |
4367 inGroupsOf:n collect:anNArgBlock |
4425 inGroupsOf:n collect:anNArgBlock |
4368 "evaluate the argument, anNArgBlock for every group of n elements in the collection, |
4426 "evaluate the argument, anNArgBlock for every group of n elements in the collection, |
4369 and collect the results. |
4427 and collect the results. |
4370 The block is called with n arguments for group of n consecutive elements in the receiver. |
4428 The block is called with n arguments for group of n consecutive elements in the receiver. |
4371 An error will be reported, if the number of elements in the receiver |
4429 An error will be reported, if the number of elements in the receiver |
4717 aThreeArgBlock |
4775 aThreeArgBlock |
4718 value:(self at:index) |
4776 value:(self at:index) |
4719 value:(aSequenceableCollection at:index) |
4777 value:(aSequenceableCollection at:index) |
4720 value:index. |
4778 value:index. |
4721 ] |
4779 ] |
|
4780 |
4722 " |
4781 " |
4723 #(one two three four five six) |
4782 #(one two three four five six) |
4724 with:(1 to:10) |
4783 with:(1 to:10) |
4725 do:[:el1 :el2 | Transcript show:el1; space; showCR:el2] |
4784 doWithIndex:[:el1 :el2 :idx| Transcript show:idx; space; show:el1; space; showCR:el2] |
4726 " |
4785 " |
4727 |
4786 |
4728 "Created: / 05-07-2006 / 18:07:11 / fm" |
4787 "Created: / 05-07-2006 / 18:07:11 / fm" |
|
4788 "Modified (comment): / 08-01-2012 / 17:18:59 / cg" |
4729 ! ! |
4789 ! ! |
4730 |
4790 |
4731 !SequenceableCollection methodsFor:'filling & replacing'! |
4791 !SequenceableCollection methodsFor:'filling & replacing'! |
4732 |
4792 |
4733 atAllPut:anObject |
4793 atAllPut:anObject |
7813 the best possible for all situations (quickSort has O-square worst |
7873 the best possible for all situations (quickSort has O-square worst |
7814 case behavior). See also #randomizedSort: for a version with better |
7874 case behavior). See also #randomizedSort: for a version with better |
7815 worstCase behavior (but worse average & bestCase behavior)" |
7875 worstCase behavior (but worse average & bestCase behavior)" |
7816 |
7876 |
7817 self quickSortWith:aCollection |
7877 self quickSortWith:aCollection |
|
7878 |
|
7879 " |
|
7880 |indices names| |
|
7881 |
|
7882 names := #('nine' 'five' 'eight' 'one' 'four' 'two') copy. |
|
7883 indices := #(9 5 8 1 4 2) copy. |
|
7884 indices sortWith:names. |
|
7885 names. |
|
7886 indices |
|
7887 " |
|
7888 |
|
7889 "Modified (comment): / 18-01-2012 / 11:30:01 / cg" |
7818 ! |
7890 ! |
7819 |
7891 |
7820 sortedBy:aBlock |
7892 sortedBy:aBlock |
7821 "Create a copy that is sorted. Sort criteria is the block that accepts two arguments. |
7893 "Create a copy that is sorted. Sort criteria is the block that accepts two arguments. |
7822 When the block is true, the first arg goes first ([:a :b | a > b] sorts in descending order)." |
7894 When the block is true, the first arg goes first ([:a :b | a > b] sorts in descending order)." |