class Dhall::Optional

Public Class Methods

as_dhall() click to toggle source
# File lib/dhall/ast.rb, line 580
def self.as_dhall
        Builtins[:Natural]
end
decode(type, value=nil) click to toggle source
# File lib/dhall/binary.rb, line 104
def self.decode(type, value=nil)
        if value.nil?
                OptionalNone.new(value_type: Dhall.decode(type))
        else
                Optional.new(
                        value:      Dhall.decode(value),
                        value_type: type.nil? ? type : Dhall.decode(type)
                )
        end
end
for(value, type: nil) click to toggle source
# File lib/dhall/ast.rb, line 572
def self.for(value, type: nil)
        if value.nil?
                OptionalNone.new(value_type: type)
        else
                Optional.new(value: value, value_type: type)
        end
end
new(normalized: false, **attrs) click to toggle source
Calls superclass method
# File lib/dhall/ast.rb, line 584
def initialize(normalized: false, **attrs)
        @normalized = normalized
        super(**attrs)
end

Public Instance Methods

as_json() click to toggle source
# File lib/dhall/ast.rb, line 610
def as_json
        [5, @normalized ? nil : value_type&.as_json, value.as_json]
end
map(type: nil, &block) click to toggle source
# File lib/dhall/ast.rb, line 598
def map(type: nil, &block)
        with(value: block[value], value_type: type)
end
normalize() click to toggle source
# File lib/dhall/normalize.rb, line 269
def normalize
        with(
                value:      value.normalize,
                value_type: value_type&.normalize,
                normalized: true
        )
end
reduce(_, &block) click to toggle source
# File lib/dhall/ast.rb, line 602
def reduce(_, &block)
        block[value]
end
to_s() click to toggle source
# File lib/dhall/ast.rb, line 606
def to_s
        value.to_s
end
type() click to toggle source
# File lib/dhall/ast.rb, line 589
def type
        return unless value_type

        Dhall::Application.new(
                function: Builtins[:Optional],
                argument: value_type
        )
end