Sha256: 50e9e87d27fc266bf8f01d707f01e8a56ce50190ab966c2cb13d6d8ba96151af

Contents?: true

Size: 690 Bytes

Versions: 18

Compression:

Stored size: 690 Bytes

Contents

module SoberSwag
  module Nodes
    ##
    # Base class for nodes that contain arrays of other nodes.
    # This is very different from an attribute representing a node which *is* an array of some element type!!
    class Array < Base
      def initialize(elements)
        @elements = elements
      end

      attr_reader :elements

      def map(&block)
        self.class.new(elements.map { |elem| elem.map(&block) })
      end

      def cata(&block)
        block.call(self.class.new(elements.map { |elem| elem.cata(&block) }))
      end

      def deconstruct
        @elements
      end

      def deconstruct_keys(_keys)
        { elements: @elements }
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sober_swag-0.19.0 lib/sober_swag/nodes/array.rb
sober_swag-0.18.0 lib/sober_swag/nodes/array.rb
sober_swag-0.17.0 lib/sober_swag/nodes/array.rb
sober_swag-0.16.0 lib/sober_swag/nodes/array.rb
sober_swag-0.15.0 lib/sober_swag/nodes/array.rb
sober_swag-0.14.0 lib/sober_swag/nodes/array.rb
sober_swag-0.13.0 lib/sober_swag/nodes/array.rb
sober_swag-0.12.0 lib/sober_swag/nodes/array.rb
sober_swag-0.11.0 lib/sober_swag/nodes/array.rb
sober_swag-0.10.0 lib/sober_swag/nodes/array.rb
sober_swag-0.9.0 lib/sober_swag/nodes/array.rb
sober_swag-0.8.0 lib/sober_swag/nodes/array.rb
sober_swag-0.7.0 lib/sober_swag/nodes/array.rb
sober_swag-0.6.0 lib/sober_swag/nodes/array.rb
sober_swag-0.5.0 lib/sober_swag/nodes/array.rb
sober_swag-0.4.0 lib/sober_swag/nodes/array.rb
sober_swag-0.3.0 lib/sober_swag/nodes/array.rb
sober_swag-0.2.0 lib/sober_swag/nodes/array.rb