class ::Regexp class NegRegexp def initialize r @rx = r end def match l ! @rx.match( l) end def =~ l ! @rx =~ l end def -@ @rx end end def -@ NegRegexp.new self end end class ::Object def to_fun meth = nil Functional.new self, meth end end class Counter include Enumerable attr_reader :c def initialize first = nil, step = nil @c, @step = first || 0, step || 1 end def next; @c += @step end def to_i; c.to_i end def to_f; c.to_f end def + i @c += @step*i end def each &e loop { e.call self; self.next } end end class Functional def self.__version__() '0.1.4' end include Enumerable class DEFAULT end class Base attr_reader :exe attr_accessor :next attr_reader :caller def initialize &e @caller = Kernel.caller.first @exe = e end def base_fun *a @next.call *a end alias call base_fun def end @next.end end def clean @next.clean end def to_proc method( :call).to_proc end end class Collect @buf.size @next.call @buf @buf.clear end end alias call slice_fun def end @next.call @buf @next.end end end class Cons @buf.size class < @buf.size @next.end end end class Pager [ [0, _A], [1, _B], ..., [_I, _C], ..., [_N, _D]] # [ [_A|_As], [_B|_Bs], ..., [_C|_Cs], ..., [_D|_Ds] ] ==> [ [0,_A|_As], [1,_B|_Bs], ..., [_I,_C|_Cs], ..., [_N,_D|_Ds] ] def with_index &exe i = 0 exe ||= Array.method :[] push Collect.new {|*a| exe.call i, *a; i += 1 } end def slice n, &exe push Slice.new( n) block_given? ? self.collect( &exe) : self end def cons n, &exe push Cons.new( n) block_given? ? self.collect( &exe) : self end def tap &exe push Tap.new( &exe) end class Save < Base attr_reader :db def initialize db @db = db end def call k, *v @db[ k] = v.length == 1 ? v.first : v end end def save db push Save.new( db) end end