code-ruby 3.1.2 → 4.0.0

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/code +97 -20
  4. data/lib/code/concerns/shared.rb +331 -15
  5. data/lib/code/format.rb +15 -1
  6. data/lib/code/network.rb +87 -0
  7. data/lib/code/node/call.rb +79 -2
  8. data/lib/code/node/call_argument.rb +14 -0
  9. data/lib/code/node/code.rb +5 -4
  10. data/lib/code/node/function_parameter.rb +7 -4
  11. data/lib/code/node/list.rb +29 -1
  12. data/lib/code/object/base_64.rb +132 -6
  13. data/lib/code/object/boolean.rb +60 -0
  14. data/lib/code/object/class.rb +138 -2
  15. data/lib/code/object/code.rb +111 -3
  16. data/lib/code/object/context.rb +57 -1
  17. data/lib/code/object/cryptography.rb +63 -0
  18. data/lib/code/object/date.rb +13339 -462
  19. data/lib/code/object/decimal.rb +1725 -0
  20. data/lib/code/object/dictionary.rb +1790 -11
  21. data/lib/code/object/duration.rb +28 -0
  22. data/lib/code/object/function.rb +261 -23
  23. data/lib/code/object/global.rb +534 -1
  24. data/lib/code/object/html.rb +179 -7
  25. data/lib/code/object/http.rb +244 -14
  26. data/lib/code/object/ics.rb +75 -13
  27. data/lib/code/object/identifier_list.rb +17 -2
  28. data/lib/code/object/integer.rb +1937 -2
  29. data/lib/code/object/json.rb +75 -1
  30. data/lib/code/object/list.rb +3383 -10
  31. data/lib/code/object/nothing.rb +53 -0
  32. data/lib/code/object/number.rb +110 -0
  33. data/lib/code/object/parameter.rb +140 -0
  34. data/lib/code/object/range.rb +576 -14
  35. data/lib/code/object/smtp.rb +95 -12
  36. data/lib/code/object/string.rb +944 -3
  37. data/lib/code/object/super.rb +10 -1
  38. data/lib/code/object/time.rb +13358 -498
  39. data/lib/code/object/url.rb +65 -0
  40. data/lib/code/object.rb +543 -0
  41. data/lib/code/parser.rb +161 -24
  42. data/lib/code-ruby.rb +3 -0
  43. data/lib/code.rb +30 -3
  44. metadata +135 -84
  45. data/.github/dependabot.yml +0 -15
  46. data/.github/workflows/ci.yml +0 -38
  47. data/.gitignore +0 -30
  48. data/.node-version +0 -1
  49. data/.npm-version +0 -1
  50. data/.prettierignore +0 -2
  51. data/.rspec +0 -1
  52. data/.rubocop.yml +0 -140
  53. data/.ruby-version +0 -1
  54. data/.tool-versions +0 -3
  55. data/AGENTS.md +0 -43
  56. data/Gemfile +0 -22
  57. data/Gemfile.lock +0 -292
  58. data/Rakefile +0 -5
  59. data/bin/bundle +0 -123
  60. data/bin/bundle-audit +0 -31
  61. data/bin/bundler-audit +0 -31
  62. data/bin/dorian +0 -31
  63. data/bin/rspec +0 -31
  64. data/bin/rubocop +0 -31
  65. data/bin/test +0 -5
  66. data/code-ruby.gemspec +0 -34
  67. data/docs/precedence.txt +0 -36
  68. data/package-lock.json +0 -14
  69. data/package.json +0 -7
  70. data/spec/bin/code_spec.rb +0 -48
  71. data/spec/code/format_spec.rb +0 -153
  72. data/spec/code/node/call_spec.rb +0 -11
  73. data/spec/code/object/boolean_spec.rb +0 -18
  74. data/spec/code/object/cryptography_spec.rb +0 -25
  75. data/spec/code/object/decimal_spec.rb +0 -50
  76. data/spec/code/object/dictionary_spec.rb +0 -98
  77. data/spec/code/object/function_spec.rb +0 -268
  78. data/spec/code/object/http_spec.rb +0 -33
  79. data/spec/code/object/ics_spec.rb +0 -50
  80. data/spec/code/object/integer_spec.rb +0 -42
  81. data/spec/code/object/list_spec.rb +0 -22
  82. data/spec/code/object/nothing_spec.rb +0 -14
  83. data/spec/code/object/range_spec.rb +0 -23
  84. data/spec/code/object/string_spec.rb +0 -26
  85. data/spec/code/parser/boolean_spec.rb +0 -11
  86. data/spec/code/parser/chained_call_spec.rb +0 -16
  87. data/spec/code/parser/dictionary_spec.rb +0 -18
  88. data/spec/code/parser/function_spec.rb +0 -16
  89. data/spec/code/parser/group_spec.rb +0 -11
  90. data/spec/code/parser/if_modifier_spec.rb +0 -18
  91. data/spec/code/parser/list_spec.rb +0 -17
  92. data/spec/code/parser/number_spec.rb +0 -11
  93. data/spec/code/parser/string_spec.rb +0 -20
  94. data/spec/code/parser_spec.rb +0 -52
  95. data/spec/code/type_spec.rb +0 -21
  96. data/spec/code_spec.rb +0 -717
  97. data/spec/spec_helper.rb +0 -21
  98. data/spec/zeitwerk/loader_spec.rb +0 -7
@@ -3,6 +3,294 @@
3
3
  class Code
4
4
  class Object
5
5
  class Range < Object
6
+ CLASS_DOCUMENTATION = {
7
+ name: "Range",
8
+ description: "represents inclusive or exclusive sequences between comparable bounds.",
9
+ examples: [
10
+ "1..3",
11
+ "1...3",
12
+ "(1..3).to_list"
13
+ ]
14
+ }.freeze
15
+ INSTANCE_FUNCTIONS = {
16
+ "all?" => {
17
+ name: "all?",
18
+ description: "returns whether every item in the range matches a function.",
19
+ examples: [
20
+ "(1..3).all?((x) => { x > 0 })",
21
+ "(1..3).all?((x) => { x < 4 })",
22
+ "(1..3).all?((x) => { x < 3 })"
23
+ ]
24
+ },
25
+ "any?" => {
26
+ name: "any?",
27
+ description: "returns whether any item in the range matches a function.",
28
+ examples: [
29
+ "(1..3).any?((x) => { x == 2 })",
30
+ "(1..3).any?((x) => { x == 1 })",
31
+ "(1..3).any?((x) => { x > 3 })"
32
+ ]
33
+ },
34
+ "none?" => {
35
+ name: "none?",
36
+ description: "returns whether no items in the range match a function.",
37
+ examples: [
38
+ "(1..3).none?((x) => { x > 3 })",
39
+ "(1..3).none?((x) => { x == 2 })",
40
+ "(1..3).none?((x) => { x < 0 })"
41
+ ]
42
+ },
43
+ "each" => {
44
+ name: "each",
45
+ description: "calls a function for each item in the range and returns the range.",
46
+ examples: [
47
+ "(1..3).each((x) => { x })",
48
+ "(:a..:c).each((x) => { x })",
49
+ "(1...3).each((x) => { x })"
50
+ ]
51
+ },
52
+ "reverse_each" => {
53
+ name: "reverse_each",
54
+ description: "calls a function for each item in the range in reverse order.",
55
+ examples: [
56
+ "(1..3).reverse_each((x) => { x })",
57
+ "(:a..:c).reverse_each((x) => { x })",
58
+ "(1...3).reverse_each((x) => { x })"
59
+ ]
60
+ },
61
+ "include?" => {
62
+ name: "include?",
63
+ description: "returns whether the range includes a value.",
64
+ examples: [
65
+ "(1..3).include?(2)",
66
+ "(1..3).include?(4)",
67
+ "(:a..:c).include?(:b)"
68
+ ]
69
+ },
70
+ "member?" => {
71
+ name: "member?",
72
+ description: "returns whether the range includes a value.",
73
+ examples: [
74
+ "(1..3).member?(2)",
75
+ "(1..3).member?(4)",
76
+ "(:a..:c).member?(:b)"
77
+ ]
78
+ },
79
+ "cover?" => {
80
+ name: "cover?",
81
+ description: "returns whether a value is between the range bounds.",
82
+ examples: [
83
+ "(1..3).cover?(2)",
84
+ "(1..3).cover?(4)",
85
+ "(:a..:c).cover?(:b)"
86
+ ]
87
+ },
88
+ "overlap?" => {
89
+ name: "overlap?",
90
+ description: "returns whether the range overlaps another range.",
91
+ examples: [
92
+ "(1..3).overlap?(2..4)",
93
+ "(1..3).overlap?(4..6)",
94
+ "(:a..:c).overlap?(:b..:d)"
95
+ ]
96
+ },
97
+ "empty?" => {
98
+ name: "empty?",
99
+ description: "returns whether the range is empty.",
100
+ examples: [
101
+ "(1..3).empty?",
102
+ "(1...1).empty?",
103
+ "(:a..:c).empty?"
104
+ ]
105
+ },
106
+ "begin" => {
107
+ name: "begin",
108
+ description: "returns the starting bound of the range.",
109
+ examples: [
110
+ "(1..3).begin",
111
+ "(:a..:c).begin",
112
+ "(1...3).begin"
113
+ ]
114
+ },
115
+ "end" => {
116
+ name: "end",
117
+ description: "returns the ending bound of the range.",
118
+ examples: [
119
+ "(1..3).end",
120
+ "(:a..:c).end",
121
+ "(1...3).end"
122
+ ]
123
+ },
124
+ "exclude_end?" => {
125
+ name: "exclude_end?",
126
+ description: "returns whether the range excludes its ending bound.",
127
+ examples: [
128
+ "(1..3).exclude_end?",
129
+ "(1...3).exclude_end?",
130
+ "(:a...:c).exclude_end?"
131
+ ]
132
+ },
133
+ "first" => {
134
+ name: "first",
135
+ description: "returns the first item in the range.",
136
+ examples: [
137
+ "(1..3).first",
138
+ "(2..4).first",
139
+ "(:a..:c).first"
140
+ ]
141
+ },
142
+ "last" => {
143
+ name: "last",
144
+ description: "returns the last item in the range.",
145
+ examples: [
146
+ "(1..3).last",
147
+ "(2..4).last",
148
+ "(:a..:c).last"
149
+ ]
150
+ },
151
+ "minimum" => {
152
+ name: "minimum",
153
+ description: "returns the minimum item in the range.",
154
+ examples: [
155
+ "(1..3).minimum",
156
+ "(:a..:c).minimum",
157
+ "(3..1).minimum"
158
+ ]
159
+ },
160
+ "maximum" => {
161
+ name: "maximum",
162
+ description: "returns the maximum item in the range.",
163
+ examples: [
164
+ "(1..3).maximum",
165
+ "(:a..:c).maximum",
166
+ "(3..1).maximum"
167
+ ]
168
+ },
169
+ "minimum_maximum" => {
170
+ name: "minimum_maximum",
171
+ description: "returns the minimum and maximum items as a list.",
172
+ examples: [
173
+ "(1..3).minimum_maximum",
174
+ "(:a..:c).minimum_maximum",
175
+ "(3..1).minimum_maximum"
176
+ ]
177
+ },
178
+ "map" => {
179
+ name: "map",
180
+ description: "returns a list with each item transformed by a function.",
181
+ examples: [
182
+ "(1..3).map((x) => { x + 1 })",
183
+ "(1..3).map((x) => { x.to_string })",
184
+ "(:a..:c).map((x) => { x.to_string })"
185
+ ]
186
+ },
187
+ "select" => {
188
+ name: "select",
189
+ description: "returns a list of items matched by a function.",
190
+ examples: [
191
+ "(1..3).select((x) => { x > 1 })",
192
+ "(1..3).select((x) => { x < 3 })",
193
+ "(:a..:c).select((x) => { x > :a })"
194
+ ]
195
+ },
196
+ "reject" => {
197
+ name: "reject",
198
+ description: "returns a list of items not matched by a function.",
199
+ examples: [
200
+ "(1..3).reject((x) => { x > 1 })",
201
+ "(1..3).reject((x) => { x < 3 })",
202
+ "(:a..:c).reject((x) => { x > :a })"
203
+ ]
204
+ },
205
+ "reduce" => {
206
+ name: "reduce",
207
+ description: "combines items in the range with a function.",
208
+ examples: [
209
+ "(1..3).reduce((sum, x) => { sum + x })",
210
+ "(1..3).reduce((product, x) => { product * x })",
211
+ "(2..4).reduce((sum, x) => { sum + x })"
212
+ ]
213
+ },
214
+ "step" => {
215
+ name: "step",
216
+ description: "returns a list of items separated by a step size.",
217
+ examples: [
218
+ "(1..5).step(2)",
219
+ "(1..5).step(1)",
220
+ "(1...5).step(2)"
221
+ ]
222
+ },
223
+ "binary_search" => {
224
+ name: "binary_search",
225
+ description: "returns the first item matched by binary search.",
226
+ examples: [
227
+ "(1..10).binary_search((x) => { x >= 5 })",
228
+ "(1..10).binary_search((x) => { x > 10 })",
229
+ "(1..3).binary_search((x) => { x >= 2 })"
230
+ ]
231
+ },
232
+ "sample" => {
233
+ name: "sample",
234
+ description: "returns a random item from the range.",
235
+ examples: [
236
+ "(1..3).sample",
237
+ "(2..4).sample",
238
+ "(:a..:c).sample"
239
+ ]
240
+ },
241
+ "size" => {
242
+ name: "size",
243
+ description: "returns the number of items in the range.",
244
+ examples: [
245
+ "(1..3).size",
246
+ "(1...3).size",
247
+ "(:a..:c).size"
248
+ ]
249
+ },
250
+ "count" => {
251
+ name: "count",
252
+ description: "returns the number of items, optionally matched by a function.",
253
+ examples: [
254
+ "(1..3).count",
255
+ "(1...3).count",
256
+ "(1..5).count((x) => { x.even? })"
257
+ ]
258
+ },
259
+ "to_list" => {
260
+ name: "to_list",
261
+ description: "returns the range items as a list.",
262
+ examples: [
263
+ "(1..3).to_list",
264
+ "(1...3).to_list",
265
+ "(:a..:c).to_list"
266
+ ]
267
+ },
268
+ "entries" => {
269
+ name: "entries",
270
+ description: "returns the range items as a list.",
271
+ examples: [
272
+ "(1..3).entries",
273
+ "(1...3).entries",
274
+ "(:a..:c).entries"
275
+ ]
276
+ },
277
+ "to_dictionary" => {
278
+ name: "to_dictionary",
279
+ description: "returns a dictionary built from indexed range items.",
280
+ examples: [
281
+ "(1..3).to_dictionary",
282
+ "(1...3).to_dictionary",
283
+ "(:a..:c).to_dictionary"
284
+ ]
285
+ }
286
+ }.freeze
287
+
288
+ def self.function_documentation(scope)
289
+ return INSTANCE_FUNCTIONS if scope == :instance
290
+
291
+ {}
292
+ end
293
+
6
294
  attr_reader :code_left, :code_right, :code_options, :code_exclude_end
7
295
 
8
296
  def initialize(*args, **kargs, &_block)
@@ -47,30 +335,90 @@ class Code
47
335
  when "any?"
48
336
  sig(args) { Function }
49
337
  code_any?(code_value, **globals)
338
+ when "none?"
339
+ sig(args) { Function }
340
+ code_none?(code_value, **globals)
50
341
  when "each"
51
342
  sig(args) { Function }
52
343
  code_each(code_value, **globals)
344
+ when "reverse_each"
345
+ sig(args) { Function }
346
+ code_reverse_each(code_value, **globals)
347
+ when "include?"
348
+ sig(args) { Object }
349
+ code_include?(code_value)
350
+ when "member?"
351
+ sig(args) { Object }
352
+ code_member?(code_value)
353
+ when "cover?"
354
+ sig(args) { Object }
355
+ code_cover?(code_value)
356
+ when "overlap?"
357
+ sig(args) { Range }
358
+ code_overlap?(code_value)
359
+ when "empty?"
360
+ sig(args)
361
+ code_empty?
362
+ when "begin"
363
+ sig(args)
364
+ code_begin
365
+ when "end"
366
+ sig(args)
367
+ code_end
368
+ when "exclude_end?"
369
+ sig(args)
370
+ code_exclude_end?
53
371
  when "first"
54
372
  sig(args)
55
373
  code_first
56
374
  when "last"
57
375
  sig(args)
58
376
  code_last
377
+ when "minimum"
378
+ sig(args)
379
+ code_minimum
380
+ when "maximum"
381
+ sig(args)
382
+ code_maximum
383
+ when "minimum_maximum"
384
+ sig(args)
385
+ code_minimum_maximum
59
386
  when "map"
60
387
  sig(args) { Function }
61
388
  code_map(code_value, **globals)
62
389
  when "select"
63
390
  sig(args) { Function }
64
391
  code_select(code_value, **globals)
392
+ when "reject"
393
+ sig(args) { Function }
394
+ code_reject(code_value, **globals)
395
+ when "reduce"
396
+ sig(args) { Function }
397
+ code_reduce(code_value, **globals)
65
398
  when "step"
66
- sig(args) { Integer | Decimal }
67
- code_step(code_value)
399
+ sig(args) { [(Integer | Decimal).maybe, Function.maybe] }
400
+ code_step(*code_arguments.raw, **globals)
401
+ when "binary_search"
402
+ sig(args) { Function }
403
+ code_binary_search(code_value, **globals)
68
404
  when "sample"
69
405
  sig(args)
70
406
  code_sample
407
+ when "size"
408
+ sig(args)
409
+ code_size
410
+ when "count"
411
+ sig(args) { Function.maybe }
412
+ code_count(code_value, **globals)
71
413
  when "to_list"
72
414
  sig(args)
73
415
  code_to_list
416
+ when "entries"
417
+ sig(args)
418
+ code_entries
419
+ when "to_dictionary"
420
+ sig(args)
421
+ code_to_dictionary
74
422
  else
75
423
  super
76
424
  end
@@ -120,6 +468,28 @@ class Code
120
468
  e.code_value
121
469
  end
122
470
 
471
+ def code_none?(argument, **globals)
472
+ code_argument = argument.to_code
473
+
474
+ index = 0
475
+
476
+ Boolean.new(
477
+ raw.none? do |code_element|
478
+ code_argument
479
+ .call(
480
+ arguments: List.new([code_element, Integer.new(index), self]),
481
+ **globals
482
+ )
483
+ .truthy?
484
+ .tap { index += 1 }
485
+ rescue Error::Next => e
486
+ e.code_value.truthy?.tap { index += 1 }
487
+ end
488
+ )
489
+ rescue Error::Break => e
490
+ e.code_value
491
+ end
492
+
123
493
  def code_each(argument, **globals)
124
494
  code_argument = argument.to_code
125
495
 
@@ -137,6 +507,59 @@ class Code
137
507
  e.code_value
138
508
  end
139
509
 
510
+ def code_reverse_each(argument, **globals)
511
+ code_argument = argument.to_code
512
+
513
+ raw.reverse_each.with_index do |code_element, index|
514
+ code_argument.call(
515
+ arguments: List.new([code_element, Integer.new(index), self]),
516
+ **globals
517
+ )
518
+ rescue Error::Next => e
519
+ e.code_value
520
+ end
521
+
522
+ self
523
+ rescue Error::Break => e
524
+ e.code_value
525
+ end
526
+
527
+ def code_include?(value)
528
+ code_value = value.to_code
529
+ Boolean.new(raw.include?(code_value))
530
+ end
531
+
532
+ def code_member?(value)
533
+ code_include?(value)
534
+ end
535
+
536
+ def code_cover?(value)
537
+ code_value = value.to_code
538
+ Boolean.new(raw.cover?(code_value))
539
+ end
540
+
541
+ def code_overlap?(range)
542
+ code_range = range.to_code
543
+
544
+ Boolean.new(raw.overlap?(code_range.raw))
545
+ end
546
+
547
+ def code_empty?
548
+ Boolean.new(raw.to_a.empty?)
549
+ end
550
+
551
+ def code_begin
552
+ code_left
553
+ end
554
+
555
+ def code_end
556
+ code_right
557
+ end
558
+
559
+ def code_exclude_end?
560
+ Boolean.new(exclude_end?)
561
+ end
562
+
140
563
  def code_first
141
564
  raw.first || Nothing.new
142
565
  end
@@ -145,6 +568,18 @@ class Code
145
568
  raw.last || Nothing.new
146
569
  end
147
570
 
571
+ def code_minimum
572
+ raw.min || Nothing.new
573
+ end
574
+
575
+ def code_maximum
576
+ raw.max || Nothing.new
577
+ end
578
+
579
+ def code_minimum_maximum
580
+ List.new([code_minimum, code_maximum])
581
+ end
582
+
148
583
  def code_map(argument, **globals)
149
584
  code_argument = argument.to_code
150
585
 
@@ -179,41 +614,168 @@ class Code
179
614
  e.code_value
180
615
  end
181
616
 
617
+ def code_reject(argument, **globals)
618
+ code_argument = argument.to_code
619
+
620
+ List.new(
621
+ raw.reject.with_index do |code_element, index|
622
+ code_argument.call(
623
+ arguments: List.new([code_element, Integer.new(index), self]),
624
+ **globals
625
+ ).truthy?
626
+ rescue Error::Next => e
627
+ e.code_value.truthy?
628
+ end
629
+ )
630
+ rescue Error::Break => e
631
+ e.code_value
632
+ end
633
+
634
+ def code_reduce(argument, **globals)
635
+ code_argument = argument.to_code
636
+
637
+ index = 0
638
+
639
+ raw.reduce do |code_acc, code_element|
640
+ code_argument
641
+ .call(
642
+ arguments:
643
+ List.new([code_acc, code_element, Integer.new(index), self]),
644
+ **globals
645
+ )
646
+ .tap { index += 1 }
647
+ rescue Error::Next => e
648
+ e.code_value.tap { index += 1 }
649
+ end || Nothing.new
650
+ rescue Error::Break => e
651
+ e.code_value
652
+ end
653
+
182
654
  def exclude_end?
183
655
  code_exclude_end.truthy?
184
656
  end
185
657
 
186
- def code_step(argument)
658
+ def code_binary_search(argument, **globals)
187
659
  code_argument = argument.to_code
660
+ values = raw.to_a
661
+ lower = 0
662
+ upper = values.length - 1
663
+ result = nil
664
+
665
+ while lower <= upper
666
+ index = (lower + upper) / 2
667
+ code_element = values[index]
668
+ matched =
669
+ begin
670
+ code_argument.call(
671
+ arguments: List.new([code_element, Integer.new(index), self]),
672
+ **globals
673
+ ).truthy?
674
+ rescue Error::Next => e
675
+ e.code_value.truthy?
676
+ end
677
+
678
+ if matched
679
+ result = code_element
680
+ upper = index - 1
681
+ else
682
+ lower = index + 1
683
+ end
684
+ end
685
+
686
+ result || Nothing.new
687
+ rescue Error::Break => e
688
+ e.code_value
689
+ end
690
+
691
+ def code_step(argument = nil, function = nil, **globals)
692
+ code_argument = argument.to_code
693
+ code_function = function.to_code
694
+
695
+ if code_argument.is_a?(Function)
696
+ code_function = code_argument
697
+ code_argument = Integer.new(1)
698
+ elsif code_argument.nothing?
699
+ code_argument = Integer.new(1)
700
+ end
188
701
 
189
702
  code_list = List.new
190
703
  code_element = code_left
191
- code_list.code_append(code_element)
704
+ index = 0
705
+ step_is_positive = code_argument.code_greater(Integer.new(0)).truthy?
192
706
 
193
- code_element = code_element.code_plus(code_argument)
707
+ loop do
708
+ comparison =
709
+ if step_is_positive
710
+ exclude_end? ? code_element.code_less(code_right) : code_element.code_less_or_equal(code_right)
711
+ else
712
+ exclude_end? ? code_element.code_greater(code_right) : code_element.code_greater_or_equal(code_right)
713
+ end
194
714
 
195
- if exclude_end?
196
- while code_element.code_less(code_right).truthy?
197
- code_list.code_append(code_element)
198
- code_element = code_element.code_plus(code_argument)
199
- end
200
- else
201
- while code_element.code_less_or_equal(code_right).truthy?
715
+ break unless comparison.truthy?
716
+
717
+ if code_function.is_a?(Function)
718
+ code_function.call(
719
+ arguments: List.new([code_element, Integer.new(index), self]),
720
+ **globals
721
+ )
722
+ else
202
723
  code_list.code_append(code_element)
203
- code_element = code_element.code_plus(code_argument)
204
724
  end
725
+
726
+ index += 1
727
+ code_element = code_element.code_plus(code_argument)
205
728
  end
206
729
 
207
- code_list
730
+ code_function.is_a?(Function) ? self : code_list
731
+ rescue Error::Break => e
732
+ e.code_value
208
733
  end
209
734
 
210
735
  def code_to_list
211
736
  List.new(raw.to_a)
212
737
  end
213
738
 
739
+ def code_entries
740
+ code_to_list
741
+ end
742
+
743
+ def code_to_dictionary
744
+ code_to_list.code_to_dictionary
745
+ end
746
+
214
747
  def code_sample
215
748
  code_to_list.code_sample
216
749
  end
750
+
751
+ def code_size
752
+ Integer.new(raw.to_a.size)
753
+ end
754
+
755
+ def code_count(argument = nil, **globals)
756
+ code_argument = argument.to_code
757
+
758
+ if code_argument.nothing?
759
+ return Integer.new(raw.to_a.size)
760
+ end
761
+
762
+ index = 0
763
+ Integer.new(
764
+ raw.count do |code_element|
765
+ code_argument
766
+ .call(
767
+ arguments: List.new([code_element, Integer.new(index), self]),
768
+ **globals
769
+ )
770
+ .truthy?
771
+ .tap { index += 1 }
772
+ rescue Error::Next => e
773
+ e.code_value.truthy?.tap { index += 1 }
774
+ end
775
+ )
776
+ rescue Error::Break => e
777
+ e.code_value
778
+ end
217
779
  end
218
780
  end
219
781
  end