Class: Dhall::Optional
- Inherits:
-
Expression
show all
- Defined in:
- lib/dhall/ast.rb,
lib/dhall/binary.rb,
lib/dhall/normalize.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #as_dhall, #cache_key, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #resolve, #shift, #slice, #substitute, #to_cbor, #to_proc, #|
Constructor Details
#initialize(normalized: false, **attrs) ⇒ Optional
Returns a new instance of Optional.
486
487
488
489
|
# File 'lib/dhall/ast.rb', line 486
def initialize(normalized: false, **attrs)
@normalized = normalized
super(**attrs)
end
|
Class Method Details
.as_dhall ⇒ Object
482
483
484
|
# File 'lib/dhall/ast.rb', line 482
def self.as_dhall
Builtins[:Natural]
end
|
.decode(type, value = nil) ⇒ Object
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/dhall/binary.rb', line 93
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) ⇒ Object
474
475
476
477
478
479
480
|
# File 'lib/dhall/ast.rb', line 474
def self.for(value, type: nil)
if value.nil?
OptionalNone.new(value_type: type)
else
Optional.new(value: value, value_type: type)
end
end
|
Instance Method Details
#as_json ⇒ Object
512
513
514
|
# File 'lib/dhall/ast.rb', line 512
def as_json
[5, @normalized ? nil : value_type&.as_json, value.as_json]
end
|
#map(type: nil, &block) ⇒ Object
500
501
502
|
# File 'lib/dhall/ast.rb', line 500
def map(type: nil, &block)
with(value: block[value], value_type: type)
end
|
#normalize ⇒ Object
253
254
255
256
257
258
259
|
# File 'lib/dhall/normalize.rb', line 253
def normalize
with(
value: value.normalize,
value_type: value_type&.normalize,
normalized: true
)
end
|
#reduce(_, &block) ⇒ Object
504
505
506
|
# File 'lib/dhall/ast.rb', line 504
def reduce(_, &block)
block[value]
end
|
#to_s ⇒ Object
508
509
510
|
# File 'lib/dhall/ast.rb', line 508
def to_s
value.to_s
end
|
#type ⇒ Object
491
492
493
494
495
496
497
498
|
# File 'lib/dhall/ast.rb', line 491
def type
return unless value_type
Dhall::Application.new(
function: Builtins[:Optional],
argument: value_type
)
end
|