nrser 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nrser/char/alpha_numeric_sub.rb +9 -19
  3. data/lib/nrser/char/special.rb +5 -5
  4. data/lib/nrser/core_ext/array.rb +36 -13
  5. data/lib/nrser/core_ext/enumerable.rb +1 -0
  6. data/lib/nrser/core_ext/enumerable/find_map.rb +1 -1
  7. data/lib/nrser/core_ext/hash/bury.rb +3 -0
  8. data/lib/nrser/core_ext/hash/extract_values_at.rb +2 -2
  9. data/lib/nrser/core_ext/method/full_name.rb +1 -1
  10. data/lib/nrser/core_ext/module/method_objects.rb +1 -1
  11. data/lib/nrser/core_ext/module/source_locations.rb +27 -15
  12. data/lib/nrser/core_ext/object/lazy_var.rb +1 -1
  13. data/lib/nrser/core_ext/pathname.rb +67 -12
  14. data/lib/nrser/core_ext/pathname/subpath.rb +86 -0
  15. data/lib/nrser/core_ext/string.rb +28 -1
  16. data/lib/nrser/core_ext/symbol.rb +11 -12
  17. data/lib/nrser/errors/README.md +154 -0
  18. data/lib/nrser/errors/attr_error.rb +146 -53
  19. data/lib/nrser/errors/count_error.rb +61 -12
  20. data/lib/nrser/errors/nicer_error.rb +42 -71
  21. data/lib/nrser/errors/value_error.rb +53 -58
  22. data/lib/nrser/functions.rb +0 -2
  23. data/lib/nrser/functions/enumerable.rb +5 -17
  24. data/lib/nrser/functions/enumerable/associate.rb +14 -5
  25. data/lib/nrser/functions/enumerable/find_all_map.rb +1 -1
  26. data/lib/nrser/functions/enumerable/include_slice/array_include_slice.rb +1 -1
  27. data/lib/nrser/functions/hash/bury.rb +2 -12
  28. data/lib/nrser/functions/merge_by.rb +2 -2
  29. data/lib/nrser/functions/module/method_objects.rb +2 -2
  30. data/lib/nrser/functions/path.rb +185 -165
  31. data/lib/nrser/functions/path/normalized.rb +84 -0
  32. data/lib/nrser/functions/string.rb +4 -4
  33. data/lib/nrser/functions/text/README.md +4 -0
  34. data/lib/nrser/functions/text/format.rb +53 -0
  35. data/lib/nrser/functions/text/indentation.rb +6 -6
  36. data/lib/nrser/functions/text/word_wrap.rb +2 -2
  37. data/lib/nrser/functions/tree/map_leaves.rb +3 -3
  38. data/lib/nrser/functions/tree/map_tree.rb +2 -2
  39. data/lib/nrser/functions/tree/transform.rb +1 -18
  40. data/lib/nrser/gem_ext/README.md +4 -0
  41. data/lib/nrser/labs/README.md +8 -0
  42. data/lib/nrser/labs/config.rb +163 -0
  43. data/lib/nrser/labs/i8.rb +49 -159
  44. data/lib/nrser/labs/i8/struct.rb +167 -0
  45. data/lib/nrser/labs/i8/struct/hash.rb +140 -0
  46. data/lib/nrser/labs/i8/struct/vector.rb +149 -0
  47. data/lib/nrser/labs/i8/surjection.rb +211 -0
  48. data/lib/nrser/labs/lots/consumer.rb +19 -0
  49. data/lib/nrser/labs/lots/parser.rb +21 -1
  50. data/lib/nrser/labs/stash.rb +4 -4
  51. data/lib/nrser/log.rb +25 -21
  52. data/lib/nrser/log/appender/sync.rb +15 -11
  53. data/lib/nrser/log/formatters/color.rb +0 -3
  54. data/lib/nrser/log/formatters/mixin.rb +4 -4
  55. data/lib/nrser/log/logger.rb +54 -6
  56. data/lib/nrser/log/mixin.rb +2 -1
  57. data/lib/nrser/log/plugin.rb +6 -6
  58. data/lib/nrser/log/types.rb +46 -29
  59. data/lib/nrser/mean_streak.rb +0 -8
  60. data/lib/nrser/mean_streak/document.rb +1 -4
  61. data/lib/nrser/message.rb +3 -3
  62. data/lib/nrser/meta/README.md +4 -0
  63. data/lib/nrser/meta/lazy_attr.rb +2 -2
  64. data/lib/nrser/meta/source/location.rb +1 -1
  65. data/lib/nrser/props.rb +34 -3
  66. data/lib/nrser/props/class_methods.rb +2 -1
  67. data/lib/nrser/props/instance_methods.rb +9 -9
  68. data/lib/nrser/props/metadata.rb +4 -12
  69. data/lib/nrser/props/mutable/stash.rb +5 -2
  70. data/lib/nrser/props/prop.rb +10 -19
  71. data/lib/nrser/rspex.rb +1 -20
  72. data/lib/nrser/rspex/example_group/describe_attribute.rb +3 -0
  73. data/lib/nrser/rspex/example_group/describe_called_with.rb +9 -4
  74. data/lib/nrser/rspex/example_group/describe_case.rb +1 -0
  75. data/lib/nrser/rspex/example_group/describe_class.rb +2 -0
  76. data/lib/nrser/rspex/example_group/describe_group.rb +1 -1
  77. data/lib/nrser/rspex/example_group/describe_instance.rb +3 -1
  78. data/lib/nrser/rspex/example_group/describe_message.rb +1 -1
  79. data/lib/nrser/rspex/example_group/describe_method.rb +64 -30
  80. data/lib/nrser/rspex/example_group/describe_response_to.rb +1 -1
  81. data/lib/nrser/rspex/example_group/describe_section.rb +4 -1
  82. data/lib/nrser/rspex/example_group/describe_sent_to.rb +1 -1
  83. data/lib/nrser/rspex/example_group/describe_setup.rb +1 -0
  84. data/lib/nrser/rspex/example_group/describe_source_file.rb +1 -1
  85. data/lib/nrser/rspex/example_group/describe_spec_file.rb +4 -2
  86. data/lib/nrser/rspex/example_group/describe_when.rb +2 -1
  87. data/lib/nrser/rspex/example_group/describe_x.rb +5 -5
  88. data/lib/nrser/rspex/format.rb +0 -15
  89. data/lib/nrser/sugar/method_missing_forwarder.rb +3 -3
  90. data/lib/nrser/sys/env/path.rb +2 -28
  91. data/lib/nrser/types.rb +63 -12
  92. data/lib/nrser/types/README.md +76 -0
  93. data/lib/nrser/types/arrays.rb +192 -137
  94. data/lib/nrser/types/attributes.rb +269 -0
  95. data/lib/nrser/types/booleans.rb +134 -83
  96. data/lib/nrser/types/bounded.rb +110 -47
  97. data/lib/nrser/types/collections.rb +119 -0
  98. data/lib/nrser/types/combinators.rb +283 -196
  99. data/lib/nrser/types/doc/display_table.md +66 -0
  100. data/lib/nrser/types/eqiuvalent.rb +91 -0
  101. data/lib/nrser/types/errors/check_error.rb +5 -11
  102. data/lib/nrser/types/errors/from_string_error.rb +3 -3
  103. data/lib/nrser/types/factory.rb +287 -20
  104. data/lib/nrser/types/hashes.rb +227 -179
  105. data/lib/nrser/types/in.rb +73 -36
  106. data/lib/nrser/types/is.rb +67 -60
  107. data/lib/nrser/types/is_a.rb +141 -84
  108. data/lib/nrser/types/labels.rb +45 -16
  109. data/lib/nrser/types/maybe.rb +6 -3
  110. data/lib/nrser/types/nil.rb +64 -27
  111. data/lib/nrser/types/not.rb +92 -34
  112. data/lib/nrser/types/numbers.rb +224 -169
  113. data/lib/nrser/types/pairs.rb +113 -89
  114. data/lib/nrser/types/paths.rb +250 -137
  115. data/lib/nrser/types/responds.rb +167 -89
  116. data/lib/nrser/types/selector.rb +234 -0
  117. data/lib/nrser/types/shape.rb +136 -65
  118. data/lib/nrser/types/strings.rb +189 -63
  119. data/lib/nrser/types/symbols.rb +83 -33
  120. data/lib/nrser/types/top.rb +89 -0
  121. data/lib/nrser/types/tuples.rb +134 -98
  122. data/lib/nrser/types/type.rb +617 -505
  123. data/lib/nrser/types/when.rb +123 -98
  124. data/lib/nrser/types/where.rb +182 -91
  125. data/lib/nrser/version.rb +1 -1
  126. data/spec/lib/nrser/core_ext/pathname/subpath_spec.rb +22 -0
  127. data/spec/lib/nrser/errors/attr_error_spec.rb +68 -0
  128. data/spec/lib/nrser/errors/count_error_spec.rb +69 -0
  129. data/spec/lib/nrser/functions/path/normalize_path_spec.rb +35 -0
  130. data/spec/lib/nrser/functions/tree/map_tree_spec.rb +74 -96
  131. data/spec/lib/nrser/functions/tree/transform_spec.rb +11 -11
  132. data/spec/lib/nrser/labs/config_spec.rb +22 -0
  133. data/spec/lib/nrser/labs/i8/struct_spec.rb +39 -0
  134. data/spec/lib/nrser/types/display_spec.rb +50 -0
  135. data/spec/lib/nrser/types/paths_spec.rb +16 -10
  136. data/spec/lib/nrser/types/selector_spec.rb +125 -0
  137. data/spec/spec_helper.rb +4 -5
  138. metadata +105 -22
  139. data/lib/nrser/types/any.rb +0 -41
  140. data/lib/nrser/types/attrs.rb +0 -213
  141. data/lib/nrser/types/trees.rb +0 -42
@@ -67,17 +67,20 @@ end # class Maybe
67
67
  # @!group Type Factory Functions
68
68
  # ----------------------------------------------------------------------------
69
69
 
70
- # @!method
70
+ # @!method self.Maybe type, **options
71
71
  # Type satisfied by `nil` or the parametrized type.
72
72
  #
73
73
  # @param [Type] type
74
74
  # The type values must be if they are not `nil`.
75
75
  #
76
- # @param **options (see Type.initialize)
76
+ # @param [Hash] options (see Type.initialize)
77
77
  #
78
78
  # @return [Type]
79
79
  #
80
- def_factory :maybe do |type, **options|
80
+ def_type :Maybe,
81
+ parameterize: :type,
82
+ default_name: false,
83
+ &->( type, **options ) do
81
84
  Maybe.new type, **options
82
85
  end
83
86
 
@@ -1,28 +1,65 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ # Requirements
5
+ # ========================================================================
6
+
7
+ # Project / Package
8
+ # ------------------------------------------------------------------------
9
+
1
10
  require_relative './is'
2
-
3
- module NRSER::Types
4
- # Type for `nil`, itself and only.
5
- #
6
- # @todo
7
- # Should we have a `#from_s` that converts the empty string to `nil`?
8
- #
9
- # Kind-of seems like we would want that to be a different types so that
10
- # you can have a Nil type that is distinct from the empty string in
11
- # parsing, but also have a type that accepts the empty string and coverts
12
- # it to `nil`?
13
- #
14
- # Something like:
15
- #
16
- # type = t.empty | t.non_empty_str
17
- # type.from_s ''
18
- # # => nil
19
- # type.from_s 'blah'
20
- # # => 'blah'
21
- #
22
- def_factory(
23
- :nil,
24
- aliases: [ :null ],
25
- ) do |name: 'Nil', **options|
26
- is nil, name: name, **options
27
- end
28
- end # NRSER::Types
11
+
12
+
13
+ # Namespace
14
+ # ========================================================================
15
+
16
+ module NRSER
17
+ module Types
18
+
19
+
20
+ # Definitions
21
+ # ========================================================================
22
+
23
+ # @!group Nil Type Factories
24
+ # ----------------------------------------------------------------------------
25
+
26
+ #@!method self.Nil **options
27
+ # Type for `nil`; itself and only.
28
+ #
29
+ # @todo
30
+ # Should we have a `#from_s` that converts the empty string to `nil`?
31
+ #
32
+ # Kind-of seems like we would want that to be a different types so that
33
+ # you can have a Nil type that is distinct from the empty string in
34
+ # parsing, but also have a type that accepts the empty string and coverts
35
+ # it to `nil`?
36
+ #
37
+ # Something like:
38
+ #
39
+ # type = t.empty | t.non_empty_str
40
+ # type.from_s ''
41
+ # # => nil
42
+ # type.from_s 'blah'
43
+ # # => 'blah'
44
+ #
45
+ # @param [Hash] options
46
+ # Passed to {Type#initialize}.
47
+ #
48
+ # @return [Type]
49
+ #
50
+ def_type :Nil,
51
+ aliases: [ :null ],
52
+ # `.Nil?` would not make any sense...
53
+ maybe: false,
54
+ &->( **options ) do
55
+ is nil, **options
56
+ end # .Nil
57
+
58
+ # @!endgroup Nil Type Factories # ********************************************
59
+
60
+
61
+ # /Namespace
62
+ # ========================================================================
63
+
64
+ end # module Types
65
+ end # module NRSER
@@ -1,43 +1,101 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
+ # Requirements
5
+ # ========================================================================
6
+
7
+ # Project / Package
8
+ # ------------------------------------------------------------------------
9
+
10
+ require_relative './type'
11
+
12
+
13
+ # Namespace
14
+ # ========================================================================
15
+
16
+ module NRSER
17
+ module Types
18
+
4
19
 
5
20
  # Definitions
6
21
  # =======================================================================
7
22
 
8
- module NRSER::Types
9
-
10
- class Not < Type
11
-
12
- # Constructor
13
- # ======================================================================
14
-
15
- # Instantiate a new `NRSER::Types::Not`.
16
- def initialize type, **options
17
- super **options
18
- @type = type
19
- end # #initialize
20
-
21
-
22
- # Instance Methods
23
- # ======================================================================
24
-
25
- def test? value
26
- ! @type.test( value )
27
- end
28
-
29
-
30
- def explain
31
- "~#{ @type.name }"
32
- end
33
-
34
- end # class Not
35
-
36
-
37
- def_factory(
38
- :not,
39
- ) do |type, **options|
40
- Not.new type, **options
23
+ # Negation {Type} - A {Type} that parameterizes another {#type} by admitting
24
+ # values that the {#type} does not.
25
+ #
26
+ # @note
27
+ # Construct {Not} types using the {.Not} factory.
28
+ #
29
+ class Not < Type
30
+
31
+ # The type this one isn't.
32
+ #
33
+ # @return [Type]
34
+ #
35
+ attr_reader :type
36
+
37
+
38
+ # Constructor
39
+ # ======================================================================
40
+
41
+ # Instantiate a new `NRSER::Types::Not`.
42
+ def initialize type, **options
43
+ super **options
44
+ @type = NRSER::Types.make type
45
+ end # #initialize
46
+
47
+
48
+ # Instance Methods
49
+ # ======================================================================
50
+
51
+ def test? value
52
+ ! type.test( value )
41
53
  end
42
54
 
43
- end # module NRSER::Types
55
+
56
+ def default_symbolic
57
+ "#{ NRSER::Types.Top.symbolic }#{ COMPLEMENT }#{ type.symbolic }"
58
+ end
59
+
60
+
61
+ def default_name
62
+ "#{ NOT }#{ type.name }"
63
+ end
64
+
65
+
66
+ def explain
67
+ "#{ self.class.demod_name }<#{ type.explain }>"
68
+ end
69
+
70
+ end # class Not
71
+
72
+
73
+ # @!group Negation Type Factories
74
+ # ----------------------------------------------------------------------------
75
+
76
+ #@!method self.Not type, **options
77
+ # Negates another type.
78
+ #
79
+ # @param [TYPE] type
80
+ # The type to negate, made into one via {.make} if it's not already.
81
+ #
82
+ # @param [Hash] options
83
+ # Passed to {Type#initialize}.
84
+ #
85
+ # @return [Not]
86
+ #
87
+ def_type :Not,
88
+ default_name: false,
89
+ parameterize: :type,
90
+ &->( type, **options ) do
91
+ Not.new type, **options
92
+ end # .Not
93
+
94
+ # @!endgroup Negation Type Factories # ***************************************
95
+
96
+
97
+ # /Namespace
98
+ # ========================================================================
99
+
100
+ end # module NRSER
101
+ end #module Types
@@ -3,172 +3,227 @@ require 'nrser/types/is_a'
3
3
  require 'nrser/types/combinators'
4
4
  require 'nrser/types/bounded'
5
5
 
6
-
7
- module NRSER::Types
8
- # Parse a string into a number.
9
- #
10
- # @return [Integer]
11
- # If the string represents a whole integer.
12
- #
13
- # @return [Float]
14
- # If the string represents a decimal number.
15
- #
16
- def self.parse_number string
17
- float = Float string
18
- int = float.to_i
19
- if float == int then int else float end
20
- end
21
-
22
-
23
- # Zero
24
- # =====================================================================
25
-
26
- def_factory(
27
- :Zero,
28
- aliases: [ :zero ],
29
- ) do |from_s: method( :parse_number ), **options|
30
- is \
31
- 0,
32
- from_s: from_s,
33
- **options
34
- end
35
-
36
-
37
- # Number ({Numeric})
38
- # =====================================================================
39
-
40
- def_factory(
41
- :Number,
42
- aliases: [ :num, :number, :numeric, :Numeric ],
43
- ) do |name: 'Number', from_s: method( :parse_number ), **options|
44
- IsA.new \
45
- Numeric,
46
- from_s: from_s,
47
- **options
48
- end
49
-
50
-
51
- # Integers
52
- # =====================================================================
53
-
54
- def_factory(
55
- :Integer,
56
- aliases: [ :int, :integer, :signed ],
57
- ) do |name: 'ℤ', from_s: method( :parse_number ), **options|
58
- IsA.new \
59
- Integer,
60
- from_s: from_s,
61
- **options
62
- end
63
-
64
-
65
- # Bounded Integers
66
- # ---------------------------------------------------------------------
67
-
68
- # Positive Integer
69
- # ----------------
70
- #
71
- # Integer greater than zero.
72
- #
73
-
74
- def_factory(
75
- :PositiveInteger,
76
- aliases: [ :pos_int, :positive_int, :positive_integer ]
77
- ) do |name: 'ℤ⁺', **options|
78
- intersection \
79
- int,
80
- bounded( min: 1 ),
81
- name: name,
82
- **options
83
- end
84
-
85
- # Ugh sometimes the naturals have 0, so omit it...
86
- # singleton_class.send :alias_method, :natural, :pos_int
87
-
88
-
89
- # Negative Integer
90
- # ----------------
91
- #
92
- # Integer less than zero.
93
- #
94
-
95
- def_factory(
96
- :NegativeInteger,
97
- aliases: [ :neg_int, :negative_int, :negative_integer ],
98
- ) do |name: 'ℤ⁻', **options|
99
- intersection \
100
- int,
101
- bounded( max: -1 ),
102
- name: name,
103
- **options
104
- end
105
-
106
-
107
- # Non-Negative Integer
108
- # --------------------
109
- #
110
- # Positive integers and zero... but it seems more efficient to define these
111
- # as bounded instead of a union.
112
- #
113
-
114
- def_factory(
115
- :NonNegativeInteger,
116
- aliases: [
117
- :non_neg_int,
118
- :unsigned,
119
- :index,
120
- :non_negative_int,
121
- :non_negative_integer,
122
- ],
123
- ) do |name: 'ℕ⁰', **options|
124
- intersection \
125
- int,
126
- bounded( min: 0 ),
127
- name: name,
128
- **options
129
- end
130
-
131
-
132
- # Non-Positive Integer
133
- # --------------------
134
- #
135
- # negative integers and zero.
136
- #
137
-
138
- def_factory(
139
- :NonPositiveInteger,
140
- aliases: [ :non_pos_int, :non_positive_int, :non_positive_integer ],
141
- ) do |name: '{0}∪ℤ⁻', **options|
142
- intersection \
143
- int,
144
- bounded( max: 0 ),
145
- name: name,
146
- **options
147
- end
148
-
149
-
150
- def_factory(
151
- :Unsigned16BitInteger,
152
- aliases: [ :uint16, :ushort ],
153
- ) do |name: 'uint16', **options|
154
- intersection \
155
- int,
156
- bounded( min: 0, max: ((2 ** 16) - 1) ),
157
- name: name,
158
- **options
159
- end
160
-
161
-
162
- # TODO Move?
163
- def_factory(
164
- :UNIXPort,
165
- aliases: [ :port, ],
166
- ) do |name: 'port', **options|
167
- intersection \
168
- int,
169
- bounded( min: 1, max: (2**16 - 1) ),
170
- name: name,
171
- **options
172
- end
173
-
174
- end # NRSER::Types
6
+
7
+ # Namespace
8
+ # ========================================================================
9
+
10
+ module NRSER
11
+ module Types
12
+
13
+
14
+ # Definitions
15
+ # ========================================================================
16
+
17
+
18
+ # Parse a string into a number.
19
+ #
20
+ # @return [Integer]
21
+ # If the string represents a whole integer.
22
+ #
23
+ # @return [Float]
24
+ # If the string represents a decimal number.
25
+ #
26
+ def self.parse_number string
27
+ float = Float string
28
+ int = float.to_i
29
+ if float == int then int else float end
30
+ end
31
+
32
+
33
+ # @!group Number Type Factories
34
+ # ----------------------------------------------------------------------------
35
+
36
+ # @!method self.Numeric **options
37
+ # The Ruby {Numeric} type, which is the super-class of all number classes:
38
+ # {Integer}, {Float}, {Rational}, {Complex}.
39
+ #
40
+ # In set theory notation this would either be expressed as either:
41
+ #
42
+ # 1. ℤ
43
+ # 2.
44
+ #
45
+ # depending on how you want to thing about the embeddability of the sets
46
+ # within each other (ℤ is embeddable in ℚ, which is embeddable in ℝ, which
47
+ # is embeddable in ℂ).
48
+ #
49
+ # However, I feel like (2) is not at all useful for expressing the type,
50
+ # and I feel like the default of just using the {Type#name} as the
51
+ # {Type#symbolic} is easier to read than (1), so this type does not provide
52
+ # a `symbolic:` keyword argument.
53
+ #
54
+ # @param [Hash] options
55
+ # Passed to {Type#initialize}.
56
+ #
57
+ # @return [Type]
58
+ # A type whose members are all instances of Ruby's {Numeric} class.
59
+ #
60
+ def_type :Numeric,
61
+ aliases: [ :num, :number, :numeric ],
62
+ # symbolic: [ INTEGERS,
63
+ # RATIONALS,
64
+ # REALS,
65
+ # COMPLEXES ].join( " #{ UNION } " ),
66
+ from_s: method( :parse_number ),
67
+ &->( **options ) do
68
+ IsA.new Numeric, **options
69
+ end
70
+
71
+
72
+ # Integers
73
+ # =====================================================================
74
+
75
+ # @!method self.Integer **options
76
+ # Instances of the built-in {Integer} class.
77
+ #
78
+ # @param [Hash] options
79
+ # Passed to {Type#initialize}.
80
+ #
81
+ # @return [Type]
82
+ #
83
+ def_type :Integer,
84
+ symbolic: 'ℤ',
85
+ from_s: method( :parse_number ),
86
+ aliases: [ :int,
87
+ :integer,
88
+ :signed ],
89
+ &->( **options ) do
90
+ IsA.new Integer, **options
91
+ end
92
+
93
+
94
+ # Bounded Integers
95
+ # ---------------------------------------------------------------------
96
+
97
+ # @!method self.PositiveInteger **options
98
+ # Integers greater than zero.
99
+ #
100
+ # @param [Hash] options
101
+ # Passed to {Type#initialize}.
102
+ #
103
+ # @return [Type]
104
+ #
105
+ def_type :PositiveInteger,
106
+ symbolic: 'ℤ⁺',
107
+ aliases: [ :pos_int,
108
+ :positive_int ],
109
+ &->( **options ) do
110
+ intersection \
111
+ self.Integer,
112
+ bounded( min: 1 ),
113
+ **options
114
+ end
115
+
116
+
117
+ # @!method self.NegativeInteger **options
118
+ # Integer less than zero.
119
+ #
120
+ # @param [Hash] options
121
+ # Passed to {Type#initialize}.
122
+ #
123
+ # @return [Type]
124
+ #
125
+ def_type :NegativeInteger,
126
+ symbolic: 'ℤ⁻',
127
+ aliases: [ :neg_int,
128
+ :negative_int ],
129
+ &->( **options ) do
130
+ intersection \
131
+ self.Integer,
132
+ self.Bounded( max: -1 ),
133
+ **options
134
+ end
135
+
136
+
137
+ # @!method self.NonNegativeInteger **options
138
+ # Positive integers and zero... but it seems more efficient to define these
139
+ # as bounded instead of a union.
140
+ #
141
+ # @param [Hash] options
142
+ # Passed to {Type#initialize}.
143
+ #
144
+ # @return [Type]
145
+ #
146
+ def_type :NonNegativeInteger,
147
+ symbolic: 'ℕ⁰',
148
+ aliases: [ :non_neg_int,
149
+ :unsigned,
150
+ :index,
151
+ :non_negative_int, ],
152
+ &->( **options ) do
153
+ intersection \
154
+ self.Integer,
155
+ self.Bounded( min: 0 ),
156
+ **options
157
+ end
158
+
159
+
160
+ # @!method self.NonPositiveInteger **options
161
+ # Negative integers and zero.
162
+ #
163
+ # @param [Hash] options
164
+ # Passed to {Type#initialize}.
165
+ #
166
+ # @return [Type]
167
+ #
168
+ def_type :NonPositiveInteger,
169
+ symbolic: '{0}∪ℤ⁻',
170
+ aliases: [ :non_pos_int,
171
+ :non_positive_int,
172
+ :non_positive_integer ],
173
+ &->( **options ) do
174
+ intersection \
175
+ self.Integer,
176
+ self.Bounded( max: 0 ),
177
+ **options
178
+ end
179
+
180
+
181
+ # Etc...
182
+ # ----------------------------------------------------------------------------
183
+
184
+ #@!method self.Unsigned16BitInteger **options
185
+ # Unsigned 16-bit {Integer} type.
186
+ #
187
+ # @param [Hash] options
188
+ # Passed to {Type#initialize}.
189
+ #
190
+ # @return [Type]
191
+ #
192
+ def_type :Unsigned16BitInteger,
193
+ symbolic: 'uint16',
194
+ aliases: [ :uint16,
195
+ :ushort ],
196
+ &->( **options ) do
197
+ intersection \
198
+ self.Integer,
199
+ self.Bounded( min: 0, max: ((2 ** 16) - 1) ),
200
+ **options
201
+ end
202
+
203
+
204
+ #@!method self.UNIXPort **options
205
+ # A valid UNIX port number {Integer}, which is a 16-bit unsigned integer
206
+ # that can ot be `0`.
207
+ #
208
+ # @param [Hash] options
209
+ # Passed to {Type#initialize}.
210
+ #
211
+ # @return [Type]
212
+ #
213
+ def_type :UNIXPort,
214
+ aliases: [ :port, ],
215
+ &->( **options ) do
216
+ intersection \
217
+ self.Integer,
218
+ self.Bounded( min: 1, max: (2**16 - 1) ),
219
+ **options
220
+ end
221
+
222
+ # @!endgroup Number Type Factories # *****************************************
223
+
224
+
225
+ # /Namespace
226
+ # ========================================================================
227
+
228
+ end # module Types
229
+ end # module NRSER