Class: Dhall::If

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

#&, #*, #+, #annotate, #as_dhall, #cache_key, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #resolve, #shift, #slice, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|

Class Method Details

.decode(pred, thn, els) ⇒ Object



194
195
196
197
198
199
200
# File 'lib/dhall/binary.rb', line 194

def self.decode(pred, thn, els)
	new(
		predicate: Dhall.decode(pred),
		then:      Dhall.decode(thn),
		else:      Dhall.decode(els)
	)
end

Instance Method Details

#as_jsonObject



1112
1113
1114
# File 'lib/dhall/ast.rb', line 1112

def as_json
	[14, predicate.as_json, self.then.as_json, self.else.as_json]
end

#normalizeObject



396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/dhall/normalize.rb', line 396

def normalize
	normalized = super
	if normalized.predicate.is_a?(Bool)
		normalized.predicate.reduce(normalized.then, normalized.else)
	elsif normalized.trivial?
		normalized.predicate
	elsif normalized.then == normalized.else
		normalized.then
	else
		normalized
	end
end

#trivial?Boolean

Returns:

  • (Boolean)


409
410
411
412
# File 'lib/dhall/normalize.rb', line 409

def trivial?
	self.then == Bool.new(value: true) &&
		self.else == Bool.new(value: false)
end