class Dhall::List
Public Class Methods
as_dhall()
click to toggle source
# File lib/dhall/ast.rb, line 438 def self.as_dhall Builtins[:List] end
decode(type, *els)
click to toggle source
# File lib/dhall/binary.rb, line 87 def self.decode(type, *els) type = type.nil? ? nil : Builtins[:List].call(Dhall.decode(type)) if els.empty? EmptyList.new(type: type) else List.new(elements: els.map(&Dhall.method(:decode)), type: type) end end
new(attrs)
click to toggle source
Calls superclass method
# File lib/dhall/ast.rb, line 421 def initialize(attrs) if attrs.key?(:element_type) et = attrs.delete(:element_type) attrs[:type] = self.class.as_dhall.call(et) if et end super end
of(*args, type: nil)
click to toggle source
# File lib/dhall/ast.rb, line 430 def self.of(*args, type: nil) if args.empty? EmptyList.new(element_type: type) else List.new(elements: args, element_type: type) end end
Public Instance Methods
[](idx)
click to toggle source
# File lib/dhall/ast.rb, line 476 def [](idx) Optional.for(elements[idx.to_i], type: element_type) end
as_json()
click to toggle source
# File lib/dhall/ast.rb, line 451 def as_json [4, nil, *elements.map(&:as_json)] end
concat(other)
click to toggle source
Calls superclass method
Dhall::Expression#concat
# File lib/dhall/ast.rb, line 496 def concat(other) if other.is_a?(List) && !other.is_a?(EmptyList) with(elements: elements + other.elements) else super end end
each(&block)
click to toggle source
# File lib/dhall/ast.rb, line 463 def each(&block) elements.each(&block) self end
element_type()
click to toggle source
# File lib/dhall/ast.rb, line 442 def element_type if type.nil? elsif type.is_a?(Application) && type.function == Builtins[:List] type.argument else raise "Cannot get element_type of: #{type.inspect}" end end
first()
click to toggle source
# File lib/dhall/ast.rb, line 480 def first Optional.for(elements.first, type: element_type) end
join(sep=$,)
click to toggle source
# File lib/dhall/ast.rb, line 492 def join(sep=$,) elements.map(&:to_s).join(sep) end
last()
click to toggle source
# File lib/dhall/ast.rb, line 484 def last Optional.for(elements.last, type: element_type) end
length()
click to toggle source
# File lib/dhall/ast.rb, line 472 def length elements.length end
map(type: nil, &block)
click to toggle source
# File lib/dhall/ast.rb, line 455 def map(type: nil, &block) type = type.nil? ? nil : Builtins[:List].call(type.as_dhall) with( elements: elements.each_with_index.map(&block), type: type ) end
reduce(*z) { |x, acc| ... }
click to toggle source
# File lib/dhall/ast.rb, line 468 def reduce(*z) elements.reverse.reduce(*z) { |acc, x| yield x, acc } end
reverse()
click to toggle source
# File lib/dhall/ast.rb, line 488 def reverse with(elements: elements.reverse) end