code-ruby 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +13 -13
  3. data/.github/workflows/ci.yml +25 -24
  4. data/.npm-version +1 -0
  5. data/.rubocop.yml +14 -11
  6. data/Gemfile +5 -4
  7. data/Gemfile.lock +134 -28
  8. data/VERSION +1 -1
  9. data/bin/console +6 -0
  10. data/bin/dorian +31 -0
  11. data/code-ruby.gemspec +6 -1
  12. data/lib/code/error.rb +4 -25
  13. data/lib/code/node/code.rb +1 -1
  14. data/lib/code/node/function_parameter.rb +10 -8
  15. data/lib/code/node/while.rb +1 -1
  16. data/lib/code/object/boolean.rb +20 -16
  17. data/lib/code/object/class.rb +10 -4
  18. data/lib/code/object/code.rb +7 -3
  19. data/lib/code/object/context.rb +8 -8
  20. data/lib/code/object/date.rb +41 -7
  21. data/lib/code/object/decimal.rb +101 -56
  22. data/lib/code/object/dictionary.rb +245 -191
  23. data/lib/code/object/duration.rb +11 -7
  24. data/lib/code/object/function.rb +38 -25
  25. data/lib/code/object/global.rb +95 -42
  26. data/lib/code/object/html.rb +12 -14
  27. data/lib/code/object/http.rb +219 -0
  28. data/lib/code/object/identifier_list.rb +16 -16
  29. data/lib/code/object/integer.rb +129 -89
  30. data/lib/code/object/json.rb +18 -22
  31. data/lib/code/object/list.rb +141 -92
  32. data/lib/code/object/parameter.rb +9 -13
  33. data/lib/code/object/range.rb +77 -45
  34. data/lib/code/object/string.rb +15 -34
  35. data/lib/code/object/time.rb +17 -16
  36. data/lib/code/object.rb +126 -93
  37. data/lib/code/parser/string.rb +2 -1
  38. data/lib/code/type/sig.rb +3 -3
  39. data/lib/code-ruby.rb +119 -0
  40. data/package-lock.json +1 -1
  41. data/package.json +1 -1
  42. data/spec/code/object/http_spec.rb +91 -0
  43. data/spec/code/type_spec.rb +1 -1
  44. data/spec/code_spec.rb +10 -5
  45. data/spec/spec_helper.rb +18 -0
  46. metadata +50 -3
@@ -3,38 +3,64 @@
3
3
  class Code
4
4
  class Object
5
5
  class Dictionary < ::Code::Object
6
+ delegate :code_eight?, to: :code_size
7
+ delegate :code_five?, to: :code_size
8
+ delegate :code_four?, to: :code_size
9
+ delegate :code_nine?, to: :code_size
10
+ delegate :code_one?, to: :code_size
11
+ delegate :code_seven?, to: :code_size
12
+ delegate :code_six?, to: :code_size
13
+ delegate :code_ten?, to: :code_size
14
+ delegate :code_three?, to: :code_size
15
+ delegate :code_two?, to: :code_size
16
+ delegate :code_zero?, to: :code_size
17
+
6
18
  def initialize(*args, **kargs, &)
7
- @raw = args.map(&:to_h).reduce({}, &:merge).merge(kargs)
19
+ @raw =
20
+ args
21
+ .map do |arg|
22
+ if arg.is_an?(::Hash)
23
+ arg.transform_keys(&:to_code).transform_values(&:to_code)
24
+ elsif arg.is_a?(Dictionary)
25
+ arg.raw.transform_keys(&:to_code).transform_values(&:to_code)
26
+ elsif arg.is_a?(Node::FunctionParameter)
27
+ arg.to_h.transform_keys(&:to_code).transform_values(&:to_code)
28
+ else
29
+ {}
30
+ end
31
+ end
32
+ .reduce({}, &:merge)
33
+ .merge(kargs.transform_keys(&:to_code).transform_values(&:to_code))
8
34
  end
9
35
 
10
36
  def call(**args)
11
- operator = args.fetch(:operator, nil)
12
- arguments = args.fetch(:arguments, List.new)
37
+ code_operator = args.fetch(:operator, nil).to_code
38
+ code_arguments = args.fetch(:arguments, List.new).to_code
13
39
  globals = multi_fetch(args, *GLOBALS)
14
- value = arguments.code_first
40
+ code_value = code_arguments.code_first
15
41
 
16
- case operator.to_s
42
+ case code_operator.to_s
17
43
  when "<", "inferior"
18
44
  sig(args) { Dictionary }
19
- code_inferior(value)
45
+ code_inferior(code_value)
20
46
  when "<=", "inferior_or_equal"
21
47
  sig(args) { Dictionary }
22
- code_inferior_or_equal(value)
48
+ code_inferior_or_equal(code_value)
23
49
  when "<=>", "compare"
24
50
  sig(args) { Dictionary }
25
- code_compare(value)
51
+ code_compare(code_value)
26
52
  when ">", "superior"
27
53
  sig(args) { Dictionary }
28
- code_superior(value)
54
+ code_superior(code_value)
29
55
  when ">=", "superior_or_equal"
30
56
  sig(args) { Dictionary }
31
- code_superior_or_equal(value)
57
+ code_superior_or_equal(code_value)
32
58
  when "[]", "at", "get"
33
59
  sig(args) { Object }
34
- code_get(value)
60
+ code_get(code_value)
35
61
  when "any?"
36
62
  sig(args) { Function | Class }
37
- code_any?(value, **globals)
63
+ code_any?(code_value, **globals)
38
64
  when "clear"
39
65
  sig(args)
40
66
  code_clear
@@ -46,19 +72,19 @@ class Code
46
72
  code_compact
47
73
  when "delete"
48
74
  sig(args) { Object.repeat(1) }
49
- code_delete(*arguments.raw, **globals)
75
+ code_delete(*code_arguments.raw, **globals)
50
76
  when "delete_if"
51
77
  sig(args) { Function | Class }
52
- code_delete_if(value, **globals)
78
+ code_delete_if(code_value, **globals)
53
79
  when "delete_unless"
54
80
  sig(args) { Function | Class }
55
- code_delete_unless(value, **globals)
81
+ code_delete_unless(code_value, **globals)
56
82
  when "dig"
57
83
  sig(args) { Object.repeat(1) }
58
- code_dig(*arguments.raw)
84
+ code_dig(*code_arguments.raw)
59
85
  when "each"
60
86
  sig(args) { Function }
61
- code_each(value, **globals)
87
+ code_each(code_value, **globals)
62
88
  when "eight?"
63
89
  sig(args)
64
90
  code_eight?
@@ -67,49 +93,49 @@ class Code
67
93
  code_empty?
68
94
  when "except"
69
95
  sig(args) { Object.repeat(1) }
70
- code_except(*arguments.raw)
96
+ code_except(*code_arguments.raw)
71
97
  when "fetch"
72
98
  sig(args) { Object.repeat(1) }
73
- code_fetch(*arguments.raw, **globals)
99
+ code_fetch(*code_arguments.raw, **globals)
74
100
  when "fetch_values"
75
101
  sig(args) { Object.repeat(1) }
76
- code_fetch_values(*arguments.raw)
102
+ code_fetch_values(*code_arguments.raw)
77
103
  when "five?"
78
104
  sig(args)
79
105
  code_five?
80
106
  when "flatten"
81
107
  sig(args) { Integer.maybe }
82
- code_flatten(value)
108
+ code_flatten(code_value)
83
109
  when "four?"
84
110
  sig(args)
85
111
  code_four?
86
112
  when "has_key?"
87
113
  sig(args) { Object }
88
- code_has_key?(value)
114
+ code_has_key?(code_value)
89
115
  when "has_value?"
90
116
  sig(args) { Object }
91
- code_has_value?(value)
117
+ code_has_value?(code_value)
92
118
  when "invert"
93
119
  sig(args)
94
120
  code_invert
95
121
  when "keep_if"
96
122
  sig(args) { Function | Class }
97
- code_keep_if(value, **globals)
123
+ code_keep_if(code_value, **globals)
98
124
  when "keep_unless"
99
125
  sig(args) { Function | Class }
100
- code_keep_unless(value, **globals)
126
+ code_keep_unless(code_value, **globals)
101
127
  when "key"
102
128
  sig(args) { [Object, Function.maybe] }
103
- code_key(*arguments.raw, **globals)
129
+ code_key(*code_arguments.raw, **globals)
104
130
  when "keys"
105
131
  sig(args)
106
132
  code_keys
107
133
  when "merge"
108
134
  sig(args) { [Dictionary.repeat, Function.maybe] }
109
- code_merge(*arguments.raw, **globals)
135
+ code_merge(*code_arguments.raw, **globals)
110
136
  when "merge!"
111
137
  sig(args) { [Dictionary.repeat, Function.maybe] }
112
- code_merge!(*arguments.raw, **globals)
138
+ code_merge!(*code_arguments.raw, **globals)
113
139
  when "nine?"
114
140
  sig(args)
115
141
  code_nine?
@@ -118,10 +144,10 @@ class Code
118
144
  code_one?
119
145
  when "select!", "filter!"
120
146
  sig(args) { Function | Class }
121
- code_select!(value, **globals)
147
+ code_select!(code_value, **globals)
122
148
  when "select", "filter"
123
149
  sig(args) { Function | Class }
124
- code_select(value, **globals)
150
+ code_select(code_value, **globals)
125
151
  when "seven?"
126
152
  sig(args)
127
153
  code_seven?
@@ -142,7 +168,7 @@ class Code
142
168
  code_to_list
143
169
  when "transform_values"
144
170
  sig(args) { Function }
145
- code_transform_values(value, **globals)
171
+ code_transform_values(code_value, **globals)
146
172
  when "two?"
147
173
  sig(args)
148
174
  code_two?
@@ -152,11 +178,11 @@ class Code
152
178
  when "zero?"
153
179
  sig(args)
154
180
  code_zero?
155
- when ->(operator) { code_has_key?(String.new(operator)).truthy? }
156
- result = code_fetch(operator)
181
+ when ->(code_operator) { code_has_key?(code_operator).truthy? }
182
+ result = code_fetch(code_operator)
157
183
 
158
184
  if result.is_a?(Function)
159
- result.call(**args.merge(operator: nil))
185
+ result.call(**args, operator: nil)
160
186
  else
161
187
  sig(args)
162
188
  result
@@ -167,14 +193,16 @@ class Code
167
193
  end
168
194
 
169
195
  def code_any?(argument, **globals)
170
- if argument.is_a?(Class)
171
- Boolean.new(raw.any? { |_, value| value.is_a?(argument.raw) })
196
+ code_argument = argument.to_code
197
+
198
+ if code_argument.is_a?(Class)
199
+ Boolean.new(raw.any? { |_, value| value.is_a?(code_argument.raw) })
172
200
  else
173
201
  index = 0
174
202
 
175
203
  Boolean.new(
176
204
  raw.any? do |key, value|
177
- argument
205
+ code_argument
178
206
  .call(
179
207
  arguments: List.new([key, value, self, Integer.new(index)]),
180
208
  **globals
@@ -192,7 +220,7 @@ class Code
192
220
  end
193
221
 
194
222
  def code_compact
195
- self.class.new(raw.dup.delete_if { |_, value| value.falsy? })
223
+ Dictionary.new(raw.dup.delete_if { |_, value| value.falsy? })
196
224
  end
197
225
 
198
226
  def code_compact!
@@ -201,50 +229,44 @@ class Code
201
229
  end
202
230
 
203
231
  def code_compare(other)
204
- Integer.new(raw <=> other.raw)
232
+ code_other = other.to_code
233
+ Integer.new(raw <=> code_other.raw)
205
234
  end
206
235
 
207
- def code_delete(*arguments, index: Integer.new(0), **globals)
208
- default =
236
+ def code_delete(*arguments, index: 0, **globals)
237
+ arguments = arguments.to_code.raw
238
+ code_index = index.to_code
239
+
240
+ code_default =
209
241
  (
210
- if arguments.last.is_a?(Function) && arguments.size > 1
211
- arguments.last
212
- end
213
- )
242
+ arguments.last if arguments.last.is_a?(Function) && arguments.many?
243
+ ).to_code
214
244
 
215
- arguments = arguments[..-2] if default
216
- first = arguments.first
245
+ arguments = arguments[...-1] unless code_default.nothing?
246
+ code_first = arguments.first.to_code
217
247
 
218
248
  if arguments.one?
219
- raw.delete(first) do
220
- if default
221
- default.call(arguments: List.new([first, self, index]), **globals)
249
+ raw.delete(code_first) do
250
+ if code_default.nothing?
251
+ Nothing.new
222
252
  else
223
- raise(
224
- Code::Error::KeyNotFound,
225
- "#{first.inspect} not found on #{inspect}"
253
+ code_default.call(
254
+ arguments: List.new([code_first, self, code_index]),
255
+ **globals
226
256
  )
227
257
  end
228
258
  end
229
259
  else
230
- self.class.new(
260
+ Dictionary.new(
231
261
  arguments
232
262
  .map
233
- .with_index do |argument, index|
234
- if default
235
- [
236
- argument,
237
- code_delete(
238
- argument,
239
- default,
240
- index: Integer.new(index),
241
- **globals
242
- )
243
- ]
263
+ .with_index do |code_argument, index|
264
+ if code_default.nothing?
265
+ [code_argument, code_delete(code_argument, index:, **globals)]
244
266
  else
245
267
  [
246
- argument,
247
- code_delete(argument, index: Integer.new(index), **globals)
268
+ code_argument,
269
+ code_delete(code_argument, code_default, index:, **globals)
248
270
  ]
249
271
  end
250
272
  end
@@ -254,12 +276,15 @@ class Code
254
276
  end
255
277
 
256
278
  def code_delete_if(argument, **globals)
257
- if argument.is_a?(Class)
258
- raw.delete_if { |_, value| value.is_a?(argument.raw) }
279
+ code_argument = argument.to_code
280
+
281
+ if code_argument.is_a?(Class)
282
+ raw.delete_if { |_, value| value.is_a?(code_argument.raw) }
259
283
  else
260
- raw.delete_if.with_index do |(key, value), index|
284
+ raw.delete_if.with_index do |(code_key, code_value), index|
261
285
  argument.call(
262
- arguments: List.new([key, value, self, Integer.new(index)]),
286
+ arguments:
287
+ List.new([code_key, code_value, self, Integer.new(index)]),
263
288
  **globals
264
289
  ).truthy?
265
290
  end
@@ -269,11 +294,13 @@ class Code
269
294
  end
270
295
 
271
296
  def code_delete_unless(argument, **globals)
272
- if argument.is_a?(Class)
273
- raw.delete_if { |_, value| !value.is_a?(argument.raw) }
297
+ code_argument = argument.to_code
298
+
299
+ if code_argument.is_a?(Class)
300
+ raw.delete_if { |_, value| !value.is_a?(code_argument.raw) }
274
301
  else
275
302
  raw.delete_if.with_index do |(key, value), index|
276
- argument.call(
303
+ code_argument.call(
277
304
  arguments: List.new([key, value, self, Integer.new(index)]),
278
305
  **globals
279
306
  ).falsy?
@@ -283,13 +310,25 @@ class Code
283
310
  self
284
311
  end
285
312
 
286
- def code_dig(*)
287
- raw.dig(*) || Nothing.new
313
+ def code_dig(*arguments)
314
+ code_arguments = arguments.to_code
315
+
316
+ code_arguments
317
+ .raw
318
+ .reduce(self) do |code_acc, code_element|
319
+ if code_acc.is_a?(Dictionary) || code_acc.is_a?(List)
320
+ code_acc.code_get(code_element)
321
+ else
322
+ Nothing.new
323
+ end
324
+ end
288
325
  end
289
326
 
290
327
  def code_each(argument, **globals)
328
+ code_argument = argument.to_code
329
+
291
330
  raw.each.with_index do |(key, value), index|
292
- argument.call(
331
+ code_argument.call(
293
332
  arguments: List.new([key, value, self, Integer.new(index)]),
294
333
  **globals
295
334
  )
@@ -298,38 +337,35 @@ class Code
298
337
  self
299
338
  end
300
339
 
301
- delegate :code_eight?, to: :code_size
302
-
303
340
  def code_empty?
304
341
  Boolean.new(raw.empty?)
305
342
  end
306
343
 
307
- def code_except(*)
308
- self.class.new(raw.except(*))
344
+ def code_except(*arguments)
345
+ code_arguments = arguments.to_code
346
+ Dictionary.new(raw.except(*code_arguments.raw))
309
347
  end
310
348
 
311
349
  def code_fetch(*arguments, index: 0, **globals)
312
- default =
350
+ code_index = index.to_code
351
+ arguments = arguments.to_code.raw
352
+
353
+ code_default =
313
354
  (
314
- if arguments.last.is_a?(Function) && arguments.size > 1
315
- arguments.last
316
- end
317
- )
355
+ arguments.last if arguments.last.is_a?(Function) && arguments.many?
356
+ ).to_code
318
357
 
319
- arguments = arguments[..-2] if default
320
- first = arguments.first || Nothing.new
358
+ arguments = arguments[..-2] unless code_default.nothing?
359
+ code_first = arguments.first.to_code
321
360
 
322
361
  if arguments.one?
323
- raw.fetch(first) do
324
- if default
325
- default.call(
326
- arguments: List.new([first, Integer.new(index), self]),
327
- **globals
328
- )
362
+ raw.fetch(code_first) do
363
+ if code_default.nothing?
364
+ Nothing.new
329
365
  else
330
- raise(
331
- Error::KeyNotFound,
332
- "#{first.inspect} not found on #{inspect}"
366
+ code_default.call(
367
+ arguments: List.new([code_first, code_index, self]),
368
+ **globals
333
369
  )
334
370
  end
335
371
  end
@@ -337,11 +373,14 @@ class Code
337
373
  Dictionary.new(
338
374
  arguments
339
375
  .map
340
- .with_index do |argument, index|
341
- if default
342
- [argument, code_fetch(argument, default, index:, **globals)]
376
+ .with_index do |code_argument, index|
377
+ if code_default.nothing?
378
+ [code_argument, code_fetch(code_argument, index:, **globals)]
343
379
  else
344
- [argument, code_fetch(argument, index:, **globals)]
380
+ [
381
+ code_argument,
382
+ code_fetch(code_argument, code_default, index:, **globals)
383
+ ]
345
384
  end
346
385
  end
347
386
  .to_h
@@ -349,49 +388,55 @@ class Code
349
388
  end
350
389
  end
351
390
 
352
- def code_fetch_values(*)
353
- List.new(raw.fetch_values(*))
354
- end
391
+ def code_fetch_values(*arguments)
392
+ code_arguments = arguments.to_code
355
393
 
356
- delegate :code_five?, to: :code_size
394
+ List.new(raw.fetch_values(*code_arguments.raw))
395
+ end
357
396
 
358
397
  def code_flatten(level = nil)
359
- level = Integer.new(-1) if level.nil? || level.falsy?
360
- code_to_list.code_flatten(level)
398
+ code_level = level.to_code
399
+ code_level = Integer.new(-1) if level.nothing?
400
+ code_to_list.code_flatten(code_level)
361
401
  end
362
402
 
363
- delegate :code_four?, to: :code_size
364
-
365
403
  def code_get(key)
366
- raw[key] || Nothing.new
404
+ code_key = key.to_code
405
+ raw[code_key] || Nothing.new
367
406
  end
368
407
 
369
408
  def code_has_key?(key)
370
- Boolean.new(raw.key?(key))
409
+ code_key = key.to_code
410
+ Boolean.new(raw.key?(code_key))
371
411
  end
372
412
 
373
413
  def code_has_value?(key)
374
- Boolean.new(raw.value?(key))
414
+ code_key = key.to_code
415
+ Boolean.new(raw.value?(code_key))
375
416
  end
376
417
 
377
418
  def code_inferior(other)
378
- Boolean.new(raw < other.raw)
419
+ code_other = other.to_code
420
+ Boolean.new(raw < code_other.raw)
379
421
  end
380
422
 
381
423
  def code_inferior_or_equal(other)
382
- Boolean.new(raw <= other.raw)
424
+ code_other = other.to_code
425
+ Boolean.new(raw <= code_other.raw)
383
426
  end
384
427
 
385
428
  def code_invert
386
- self.class.new(raw.invert)
429
+ Dictionary.new(raw.invert)
387
430
  end
388
431
 
389
432
  def code_keep_if(argument, **globals)
390
- if argument.is_a?(Class)
391
- raw.keep_if { |_, value| value.is_a?(argument.raw) }
433
+ code_argument = argument.to_code
434
+
435
+ if code_argument.is_a?(Class)
436
+ raw.keep_if { |_, value| value.is_a?(code_argument.raw) }
392
437
  else
393
438
  raw.keep_if.with_index do |(key, value), index|
394
- argument.call(
439
+ code_argument.call(
395
440
  arguments: List.new([key, value, Integer.new(index), self]),
396
441
  **globals
397
442
  ).truthy?
@@ -402,16 +447,18 @@ class Code
402
447
  end
403
448
 
404
449
  def code_keep_unless(argument, **globals)
405
- if argument.is_a?(Class)
406
- raw.keep_if { |_, value| !value.is_a?(argument.raw) }
450
+ code_argument = argument.to_code
451
+
452
+ if code_argument.is_a?(Class)
453
+ raw.keep_if { |_, value| !value.is_a?(code_argument.raw) }
407
454
  else
408
455
  raw.keep_if.with_index do |(key, value), index|
409
- argument.call(
456
+ code_argument.call(
410
457
  arguments: List.new([key, value, Integer.new(index), self]),
411
458
  **globals
412
459
  ).falsy?
413
460
  rescue Error::Next => e
414
- (e.value || Nothing.new).falsy?
461
+ e.code_value.falsy?
415
462
  end
416
463
  end
417
464
 
@@ -419,14 +466,17 @@ class Code
419
466
  end
420
467
 
421
468
  def code_key(value, function = nil, **globals)
422
- if function
423
- raw.key(value) ||
424
- function.call(arguments: List.new([value, self]), **globals)
469
+ code_value = value.to_code
470
+ code_function = function.to_code
471
+
472
+ if code_function.nothing?
473
+ raw.key(code_value) || Nothing.new
425
474
  else
426
- raw.key(value) || Nothing.new
475
+ raw.key(code_value) ||
476
+ function.call(arguments: List.new([code_value, self]), **globals)
427
477
  end
428
478
  rescue Error::Next => e
429
- e.value || Nothing.new
479
+ e.code_value
430
480
  end
431
481
 
432
482
  def code_keys
@@ -434,88 +484,97 @@ class Code
434
484
  end
435
485
 
436
486
  def code_merge(*arguments, **globals)
437
- conflict =
487
+ arguments = arguments.to_code.raw
488
+
489
+ code_conflict =
438
490
  (
439
- if arguments.last.is_a?(Function) && arguments.size > 1
440
- arguments.last
441
- end
442
- )
491
+ arguments.last if arguments.last.is_a?(Function) && arguments.many?
492
+ ).to_code
443
493
 
444
- arguments = arguments[..-2] if conflict
494
+ arguments = arguments[..-2] unless code_conflict.nothing?
445
495
 
446
496
  index = 0
447
497
 
448
- self.class.new(
498
+ Dictionary.new(
449
499
  raw.merge(*arguments.map(&:raw)) do |key, old_value, new_value|
450
- if conflict
451
- conflict
500
+ if code_conflict.nothing?
501
+ new_value.to_code.tap { index += 1 }
502
+ else
503
+ code_conflict
452
504
  .call(
453
505
  arguments:
454
506
  List.new(
455
- [key, old_value, new_value, Integer.new(index), self]
507
+ [
508
+ key.to_code,
509
+ old_value.to_code,
510
+ new_value.to_code,
511
+ index.to_code,
512
+ self
513
+ ]
456
514
  ),
457
515
  **globals
458
516
  )
459
517
  .tap { index += 1 }
460
- else
461
- new_value.tap { index += 1 }
462
518
  end
463
519
  rescue Error::Next => e
464
- index += 1
465
- e.value || Nothing.new
520
+ e.code_value.tap { index += 1 }
466
521
  end
467
522
  )
468
523
  end
469
524
 
470
525
  def code_merge!(*arguments, **globals)
471
- conflict =
526
+ arguments = arguments.to_code.raw
527
+
528
+ code_conflict =
472
529
  (
473
- if arguments.last.is_a?(Function) && arguments.size > 1
474
- arguments.last
475
- end
476
- )
530
+ arguments.last if arguments.last.is_a?(Function) && arguments.many?
531
+ ).to_code
477
532
 
478
- arguments = arguments[..-2] if conflict
533
+ arguments = arguments[..-2] unless code_conflict.nothing?
479
534
 
480
535
  index = 0
481
536
 
482
537
  raw.merge!(*arguments.map(&:raw)) do |key, old_value, new_value|
483
- if conflict
484
- conflict
538
+ if code_conflict.nothing?
539
+ new_value.to_code.tap { index += 1 }
540
+ else
541
+ code_conflict
485
542
  .call(
486
543
  arguments:
487
544
  List.new(
488
- [key, old_value, new_value, Integer.new(index), self]
545
+ [
546
+ key.to_code,
547
+ old_value.to_code,
548
+ new_value.to_code,
549
+ index.to_code,
550
+ self
551
+ ]
489
552
  ),
490
553
  **globals
491
554
  )
492
555
  .tap { index += 1 }
493
- else
494
- new_value.tap { index += 1 }
495
556
  end
496
557
  rescue Error::Next => e
497
- index += 1
498
- e.value || Nothing.new
558
+ e.code_value.tap { index += 1 }
499
559
  end
500
560
 
501
561
  self
502
562
  end
503
563
 
504
- delegate :code_nine?, to: :code_size
505
-
506
- delegate :code_one?, to: :code_size
507
-
508
564
  def code_select!(argument, **globals)
509
- if argument.is_a?(Class)
510
- raw.select! { |_, value| value.is_a?(argument.raw) }
565
+ code_argument = argument.to_code
566
+
567
+ if code_argument.is_a?(Class)
568
+ raw.select! { |_, value| value.is_a?(code_argument.raw) }
511
569
  else
512
570
  raw.select!.with_index do |(key, value), index|
513
571
  argument.call(
514
- arguments: List.new([key, value, Integer.new(index), self]),
572
+ arguments:
573
+ List.new([key.to_code, value.to_code, index.to_code, self]),
515
574
  **globals
516
575
  ).truthy?
517
576
  rescue Error::Next => e
518
- (e.value || Nothing.new).truthy?
577
+ e.code_value.truthy?
519
578
  end
520
579
  end
521
580
 
@@ -523,47 +582,48 @@ class Code
523
582
  end
524
583
 
525
584
  def code_select(argument, **globals)
526
- if argument.is_a?(Class)
527
- self.class.new(raw.select { |_, value| value.is_a?(argument.raw) })
585
+ code_argument = argument.to_code
586
+
587
+ if code_argument.is_a?(Class)
588
+ Dictionary.new(
589
+ raw.select { |_, value| value.is_a?(code_argument.raw) }
590
+ )
528
591
  else
529
- self.class.new(
592
+ Dictionary.new(
530
593
  raw.select.with_index do |(key, value), index|
531
594
  argument.call(
532
- arguments: List.new([key, value, Integer.new(index), self]),
595
+ arguments:
596
+ List.new([key.to_code, value.to_code, index.to_code, self]),
533
597
  **globals
534
598
  ).truthy?
535
599
  rescue Error::Next => e
536
- (e.value || Nothing.new).truthy?
600
+ e.code_value.truthy?
537
601
  end
538
602
  )
539
603
  end
540
604
  end
541
605
 
542
606
  def code_set(key, value)
543
- raw[key] = value
544
- value
607
+ code_key = key.to_code
608
+ code_value = value.to_code
609
+ raw[code_key] = code_value
610
+ code_value
545
611
  end
546
612
 
547
- delegate :code_seven?, to: :code_size
548
-
549
- delegate :code_six?, to: :code_size
550
-
551
613
  def code_size
552
614
  Integer.new(raw.size)
553
615
  end
554
616
 
555
617
  def code_superior(other)
556
- Boolean.new(raw > other.raw)
618
+ code_other = other.to_code
619
+ Boolean.new(raw > code_other.raw)
557
620
  end
558
621
 
559
622
  def code_superior_or_equal(other)
560
- Boolean.new(raw >= other.raw)
623
+ code_other = other.to_code
624
+ Boolean.new(raw >= code_other.raw)
561
625
  end
562
626
 
563
- delegate :code_ten?, to: :code_size
564
-
565
- delegate :code_three?, to: :code_size
566
-
567
627
  def code_to_context
568
628
  Context.new(raw)
569
629
  end
@@ -572,30 +632,24 @@ class Code
572
632
  List.new(raw.to_a.map { |key_value| List.new(key_value) })
573
633
  end
574
634
 
575
- def to_h
576
- raw
577
- end
578
-
579
635
  def code_transform_values(function, **globals)
580
- self.class.new(
636
+ code_function = function.to_code
637
+
638
+ Dictionary.new(
581
639
  raw.transform_values.with_index do |value, index|
582
- function.call(
583
- arguments: List.new([value, Integer.new(index), self]),
640
+ code_function.call(
641
+ arguments: List.new([value.to_code, index.to_code, self]),
584
642
  **globals
585
643
  )
586
644
  rescue Error::Next => e
587
- e.value || Nothing.new
645
+ e.code_value
588
646
  end
589
647
  )
590
648
  end
591
649
 
592
- delegate :code_two?, to: :code_size
593
-
594
650
  def code_values
595
651
  List.new(raw.values)
596
652
  end
597
-
598
- delegate :code_zero?, to: :code_size
599
653
  end
600
654
  end
601
655
  end