| 
									
										
										
										
											2018-12-02 21:30:30 -08:00
										 |  |  | module Enumerable(T) | 
					
						
							|  |  |  |   def count_each(others) | 
					
						
							|  |  |  |     count_map = {} of T => Int32 | 
					
						
							|  |  |  |     each do |other| | 
					
						
							|  |  |  |       count_map[other] = (count_map[other]? || 0) + 1
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |     return count_map | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Rectangle | 
					
						
							|  |  |  |   def initialize(@x : Int32, @y : Int32, @width : Int32, @height : Int32) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def each_coord(&block) | 
					
						
							|  |  |  |     (@x...(@x + @width)).each do |x| | 
					
						
							|  |  |  |       (@y...(@y + @height)).each do |y| | 
					
						
							|  |  |  |         yield x, y | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2018-12-05 15:58:46 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class String | 
					
						
							|  |  |  |   def select(&block) | 
					
						
							|  |  |  |     String.build do |s| | 
					
						
							|  |  |  |       each_char do |c| | 
					
						
							|  |  |  |         s << c if yield c | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def select!(&block) | 
					
						
							|  |  |  |     i = 0
 | 
					
						
							|  |  |  |     s = size | 
					
						
							|  |  |  |     while i < s | 
					
						
							|  |  |  |       if yield [i] | 
					
						
							|  |  |  |         i += 1
 | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         s -= 1
 | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |