class SoberSwag::Nodes::List

A List of the contained element types.

Unlike {SoberSwag::Nodes::Array}, this actually models arrays. The other one is a node that is an array in terms of what it contains. Kinda confusing, but oh well.

@todo swap the names of this and {SoberSwag::Nodes::Array} so it's less confusing.

Attributes

element[R]

@return [SoberSwag::Nodes::Base]

Public Class Methods

new(element) click to toggle source

Initialize with a node representing the type of elements in the list. @param element [SoberSwag::Nodes::Base] the type

# File lib/sober_swag/nodes/list.rb, line 15
def initialize(element)
  @element = element
end

Public Instance Methods

cata(&block) click to toggle source

@see SoberSwag::Nodes::Base#cata

Maps over the element type, then this `List` type.

# File lib/sober_swag/nodes/list.rb, line 40
def cata(&block)
  block.call(
    self.class.new(
      element.cata(&block)
    )
  )
end
deconstruct() click to toggle source

@return [Array(SoberSwag::Nodes::Base)]

# File lib/sober_swag/nodes/list.rb, line 25
def deconstruct
  [element]
end
deconstruct_keys(_) click to toggle source

@return [Hash{Symbol => SoberSwag::Nodes::Base}]

the contained type wrapped in an `element:` key.
# File lib/sober_swag/nodes/list.rb, line 32
def deconstruct_keys(_)
  { element: element }
end
map(&block) click to toggle source

@see SoberSwag::Nodes::Base#map

Maps over the element type.

# File lib/sober_swag/nodes/list.rb, line 52
def map(&block)
  self.class.new(
    element.map(&block)
  )
end