Collection.st
branchjv
changeset 18963 5a18dd0c21ec
parent 18942 b48824459593
parent 18961 2047840e1521
child 19011 84c9f9410b1a
equal deleted inserted replaced
18960:6e6225b7a7d9 18963:5a18dd0c21ec
  2713 
  2713 
  2714     <resource: #obsolete>
  2714     <resource: #obsolete>
  2715     self obsoleteMethodWarning:'use #do:separatedBy:'.
  2715     self obsoleteMethodWarning:'use #do:separatedBy:'.
  2716     ^ self do:aBlock separatedBy:betweenBlock
  2716     ^ self do:aBlock separatedBy:betweenBlock
  2717 
  2717 
  2718     "
       
  2719      #(1 2 3 4) do:[:el | Transcript show:el]
       
  2720                 inBetweenDo:[ Transcript show:'-']
       
  2721 
       
  2722      (Dictionary with:(1->'one') with:(2->'two'))
       
  2723          do:[:el | Transcript showCR:el printString]
       
  2724          inBetweenDo:[ Transcript showCR:'----']
       
  2725 
       
  2726      (Dictionary with:(1->'one') with:(2->'two'))
       
  2727         associations
       
  2728          do:[:el | Transcript showCR:el printString]
       
  2729          inBetweenDo:[ Transcript showCR:'----']
       
  2730 
       
  2731     "
       
  2732 
       
  2733     "Modified: / 11.2.2000 / 11:23:15 / cg"
  2718     "Modified: / 11.2.2000 / 11:23:15 / cg"
  2734 !
  2719 !
  2735 
  2720 
  2736 do:aBlock separatedBy:betweenBlock
  2721 do:aBlock separatedBy:betweenBlock
  2737     "evaluate the argument, aBlock for each element.
  2722     "evaluate the argument, aBlock for each element.
  2780     "
  2765     "
  2781 
  2766 
  2782     "Modified: / 11.2.2000 / 11:23:15 / cg"
  2767     "Modified: / 11.2.2000 / 11:23:15 / cg"
  2783 !
  2768 !
  2784 
  2769 
       
  2770 do:aBlock whileTrue:whileBlock
       
  2771     "evaluate the argument, aBlock for each element until whileBlock
       
  2772      evaluates to false.
       
  2773      Answer the last result from evaluating aBlock."
       
  2774 
       
  2775     |result|
       
  2776 
       
  2777     self do:[:el |
       
  2778         result := aBlock value:el.
       
  2779         (whileBlock value:el) ifFalse:[
       
  2780             ^ result.
       
  2781         ]
       
  2782     ].
       
  2783     ^ result
       
  2784 
       
  2785     "Example:
       
  2786      search for the first element which is >= 99; return it.
       
  2787      remaining elements are not processed:
       
  2788 
       
  2789      #(1 2 3 4 999 5 6 7 8 9) 
       
  2790         do:[:element|
       
  2791             Transcript showCR:element.
       
  2792             element
       
  2793         ] whileTrue:[:element| element < 99]    
       
  2794     "
       
  2795 !
       
  2796 
  2785 do:aBlock without:anItem
  2797 do:aBlock without:anItem
  2786     "enumerate all elements except those equal to anItem into aBlock."
  2798     "enumerate all elements except those equal to anItem into aBlock."
  2787 
  2799 
  2788     self do:[:el |
  2800     self do:[:el |
  2789         anItem ~= el ifTrue:[ aBlock value:el ]
  2801         anItem ~= el ifTrue:[ aBlock value:el ]
  2795         do:[:el | Transcript showCR:el ]
  2807         do:[:el | Transcript showCR:el ]
  2796         without:5
  2808         without:5
  2797     "
  2809     "
  2798 
  2810 
  2799     "Created: / 28-02-2012 / 21:11:41 / cg"
  2811     "Created: / 28-02-2012 / 21:11:41 / cg"
       
  2812 !
       
  2813 
       
  2814 doWhileTrue:aBlock
       
  2815     "evaluate the argument, aBlock for each element,
       
  2816      until the block evaluates to false.
       
  2817      Answer true, if all the elements have been processed,
       
  2818      false otherwise."
       
  2819 
       
  2820 
       
  2821     self do:[:el |
       
  2822         (aBlock value:el) ifFalse:[
       
  2823             ^ false.
       
  2824         ]
       
  2825     ].
       
  2826     ^ true
       
  2827 
       
  2828     "Example:
       
  2829      search for the first element which is >= 99; return it.
       
  2830      remaining elements are not processed:
       
  2831 
       
  2832      |lastElement|
       
  2833 
       
  2834      #(1 2 3 4 999 5 6 7 8 9) 
       
  2835         doWhileTrue:[:element|
       
  2836             Transcript showCR:element.
       
  2837             lastElement := element.
       
  2838             element < 99
       
  2839         ].
       
  2840      lastElement
       
  2841     "
  2800 !
  2842 !
  2801 
  2843 
  2802 doWithExit:aBlock
  2844 doWithExit:aBlock
  2803     "evaluate the argument, aBlock for each element.
  2845     "evaluate the argument, aBlock for each element.
  2804      Passes an additional exit object, which can be used to leave
  2846      Passes an additional exit object, which can be used to leave
  4718     "return the longest common prefix of my elements (which must be sequenceableCollections).
  4760     "return the longest common prefix of my elements (which must be sequenceableCollections).
  4719      Typically used with string collections, 
  4761      Typically used with string collections, 
  4720      especially with completion of selectors or filenames."
  4762      especially with completion of selectors or filenames."
  4721 
  4763 
  4722     ^ self longestCommonPrefixCaseSensitive:ignoreCase not
  4764     ^ self longestCommonPrefixCaseSensitive:ignoreCase not
  4723 
       
  4724     "
       
  4725      #('Array' 'arrayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:true 
       
  4726      #('Array' 'arrayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:false 
       
  4727      #('Array' 'ArayedCollection' 'ARRAYOfFoo') longestCommonPrefixIgnoreCase:false   
       
  4728      #('AAA' 'A11' 'AA2') longestCommonPrefixIgnoreCase:false   
       
  4729      #('AAA' 'BBB' 'CCC') longestCommonPrefixIgnoreCase:false   
       
  4730     "
       
  4731 !
  4765 !
  4732 
  4766 
  4733 longestCommonSuffix
  4767 longestCommonSuffix
  4734     "return the longest common suffix (tail) of my elements.
  4768     "return the longest common suffix (tail) of my elements.
  4735      Typically used with string collections."
  4769      Typically used with string collections."
  4769     <resource: #obsolete>
  4803     <resource: #obsolete>
  4770     "return the longest common suffix (tail) of my elements
  4804     "return the longest common suffix (tail) of my elements
  4771      (which must be sequenceableCollections)."
  4805      (which must be sequenceableCollections)."
  4772 
  4806 
  4773     ^ self longestCommonSuffixCaseSensitive:ignoreCase not
  4807     ^ self longestCommonSuffixCaseSensitive:ignoreCase not
  4774 
       
  4775     "
       
  4776      #('Array' 'ByteArray' 'BigArray') longestCommonSuffixIgnoreCase:true 
       
  4777      #('AAA' 'BBBAA' 'CCCAAAA') longestCommonSuffixIgnoreCase:false       
       
  4778      #('AAA' 'BBB' 'CCC') longestCommonSuffixIgnoreCase:false             
       
  4779     "
       
  4780 !
  4808 !
  4781 
  4809 
  4782 max
  4810 max
  4783     "return the maximum value in the receiver collection,
  4811     "return the maximum value in the receiver collection,
  4784      using #< to compare elements.
  4812      using #< to compare elements.
  5773     "dispatch for visitor pattern; send #visitCollection:with: to aVisitor"
  5801     "dispatch for visitor pattern; send #visitCollection:with: to aVisitor"
  5774 
  5802 
  5775     ^ aVisitor visitCollection:self with:aParameter
  5803     ^ aVisitor visitCollection:self with:aParameter
  5776 ! !
  5804 ! !
  5777 
  5805 
       
  5806 
  5778 !Collection class methodsFor:'documentation'!
  5807 !Collection class methodsFor:'documentation'!
  5779 
  5808 
  5780 version
  5809 version
  5781     ^ '$Header$'
  5810     ^ '$Header$'
  5782 !
  5811 !