Sunday, 12 October 2014

Transducers in ruby-processing

Transducers may be useful in ruby-processing for dealing with all sorts of algorithmic stuff. but in many cases if your brain can take it map, might be equally good. Here is example substituting a regular map with a transducer, I will have to see if I can find a more useful example:-

                                                            
require 'transducers'                                                                
                                                                                     
class GameOfLife < Processing::App                                                
  T = Transducers                                                                    
                                                                                      
  def random_data                                                                    
    T.transduce(T.map{ rand(1000) < ALIVE_START }, :<<, [], 0..row * column)
  end                                                                                
end                                                                                  

No comments:

Post a Comment