~singpolyma/dhall-ruby

ref: 831a391f421d60eed8933d38ed3cc7149d018900 dhall-ruby/lib/dhall/util.rb -rw-r--r-- 653 bytes
831a391fStephen Paul Weber Generic subexpression_map 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module Dhall
	module Util
		class ArrayOf < ValueSemantics::ArrayOf
			def initialize(element_validator, min: 0, max: Float::INFINITY)
				@min = min
				@max = max
				super(element_validator)
			end

			def ===(other)
				super && other.length >= @min && other.length <= @max
			end
		end

		class HashOf
			def initialize(element_validator, min: 0, max: Float::INFINITY)
				@min = min
				@max = max
				@element_validator = element_validator
			end

			def ===(other)
				Hash === other &&
					other.values.all? { |x| @element_validator === x } &&
					other.size >= @min && other.size <= @max
			end
		end
	end
end