Parent

Enumerable::Recursor

Recursor “functor”.

NOTE: THIS IS A WORK IN PROGRESS!

Public Class Methods

new(enum, opts) click to toggle source
    # File lib/core/facets/enumerable/recursive.rb, line 13
13:     def initialize(enum, opts)
14:       @enum = enum
15:       @opts = opts
16:     end

Public Instance Methods

each(&b) click to toggle source

Recursive iteration over enumerables.

  [1, 2, [3, 4]].recursive.each{ |e| p e }

produces

  1
  2
  3
  4

NOTE: Technically this should check for the proper conversion method if applicable, eg. # for Array, rather than just checking the class type. In the future this may be generally supported if Facets ever adds a “class know-thy-self” library. In the meantime override in classes are required to incorporate this.

    # File lib/core/facets/enumerable/recursive.rb, line 36
36:     def each(&b)
37:       @enum.each{ |*v| process(:each, *v, &b) }
38:     end
map(&b) click to toggle source

Recursive map.

  [1, 2, ['a', 'b']].recursive.map{ |e| e.succ }
  #=> [1, 2, ['b', 'c']]
    # File lib/core/facets/enumerable/recursive.rb, line 45
45:     def map(&b)
46:       @enum.map{ |*v| process(:map, *v, &b) }
47:     end

Private Instance Methods

process(op, v, &b) click to toggle source
    # File lib/core/facets/enumerable/recursive.rb, line 57
57:     def process(op, v, &b)
58:       case v
59:       when String # b/c of 1.8
60:         b.call(v)
61:       when @enum.class
62:         v.recursive(@opts).send(op,&b)
63:       else
64:         #if @opts[:skip] && Enumerable === v
65:         #  v
66:         #else
67:           b.call(v)
68:         #end
69:       end
70:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.