ex_aequo_base 0.1.10 → 0.1.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df234a242bd18d417f8c1df61d6b25dfdfe59e0d9af1eea2c9c560cc60287f72
4
- data.tar.gz: 4792d00ba86ce36c352ed3b575df8f68fc4f7a7f37ee49d43141aaed04e5821d
3
+ metadata.gz: e6d97deba4b11a23933ae70a5a9fa71014f642c22bd05e9f08f81e82551b7ea2
4
+ data.tar.gz: 99246ab6909c6976d5f2025635c987e897f1e7dae36ab6f3e21b8ed9be2c12c8
5
5
  SHA512:
6
- metadata.gz: 7df36f9dd42146763cfb902b7550871c1365991eeaab71eef99ee169ce606566cbf298abeb63dbd79529fcd1ded14069967f5b6b576efa90d94d69be72f907e1
7
- data.tar.gz: b85818ae40aa7be88bab8e0bd62e21b653187e73a8d761d15547493d916239ec966e783ec2bdd5e6d6c7ae1d8d3a7ffea3f03b3269c991786fcf865c2f8368fa
6
+ metadata.gz: ee51acf5852165238315c8684f4d5c8542e4f550782d02965347783ae38c7457a320716d9512e18f1b67685194a7707748fcd58561392d83768c46f46545c5e7
7
+ data.tar.gz: 2fc4f4806e02f11f56ae8dad5b749de38d6522bbe212fb64fea97bd79f695cc8e18350c1a147bc0505a123cade6b755eafd27066bc80da85c3fd3420a65ea740
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExAequo
4
+ module Base
5
+ module Enumerable
6
+ class ArrayHelper
7
+
8
+ def extract
9
+ fst = @slice.first
10
+ lst = @slice.last
11
+
12
+ @middle = @ary[@slice]
13
+ @head = @ary[0...fst]
14
+
15
+ @tail = tail_slice(lst, exclude_end: @slice.exclude_end?)
16
+ [@head, @middle, @tail].map(&Array)
17
+ end
18
+
19
+ def map_slice(&blk)
20
+ extract
21
+ @head + @middle.map(&blk) + @tail
22
+ end
23
+
24
+ private
25
+ def initialize(ary, slice:)
26
+ @ary = ary
27
+ @slice = make_slice(slice)
28
+ end
29
+
30
+ def tail_slice(n, exclude_end:)
31
+ return [] if n == -1 && !exclude_end
32
+ if exclude_end
33
+ @ary[n..-1]
34
+ else
35
+ @ary[n.succ..-1]
36
+ end
37
+ end
38
+
39
+ def make_slice(slice)
40
+ case slice
41
+ when Range
42
+ slice
43
+ when Integer
44
+ slice..slice
45
+ else
46
+ raise ArgumentError, "slice #{slice.inspect} must be a Range or Integer"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ class Array
55
+
56
+ def self.to_proc = -> do Array it end
57
+
58
+ def extract_slice(slice) = ExAequo::Base::Enumerable::ArrayHelper.new(self, slice:).extract
59
+
60
+ def map_slice(slice, &blk) = ExAequo::Base::Enumerable::ArrayHelper.new(self, slice:).map_slice(&blk)
61
+
62
+ end
63
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExAequo
4
+ module Base
5
+ module Enumerable
6
+ module Hash
7
+ def maph(&blk)
8
+ inject({}) do |r, (k, v)|
9
+ blk.(k, v) => [nk, nv]
10
+ r.update(nk => nv)
11
+ end
12
+ end
13
+
14
+ def mapv(&blk)
15
+ maph { |k, v| [k, blk.(v)] }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../fn'
4
+ module ExAequo
5
+ module Base
6
+ module Enumerable
7
+ module EnumerableHelper extend self
8
+ def reduce_until_with_trigger(enum, initial:, end_triggers:, &blk)
9
+ f = Fn.mk_fun_pipeline(end_triggers)
10
+ enum.each do
11
+ return initial if f.(initial)
12
+ initial = blk.(initial, it)
13
+ end
14
+ initial
15
+ end
16
+
17
+ def reduce_while_simple(enum, initial:, &blk)
18
+ enum.each do
19
+ val = blk.(initial, it)
20
+ if val
21
+ initial = val
22
+ else
23
+ return initial
24
+ end
25
+ end
26
+ initial
27
+ end
28
+
29
+ def reduce_while_with_trigger(enum, initial:, end_triggers:, &blk)
30
+ f = Fn.mk_fun_pipeline(end_triggers)
31
+ enum.each do
32
+ val = blk.(initial, it)
33
+ # p(val:, f: f.(val))
34
+ if f.(val)
35
+ initial = val
36
+ else
37
+ return initial
38
+ end
39
+ end
40
+ initial
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'enumerable_helper'
3
+ require_subdir __FILE__
4
4
  module Enumerable
5
5
  def find_value(&blk)
6
6
  each do
@@ -13,15 +13,19 @@ module Enumerable
13
13
  def reduce_until(initial, *end_triggers, &blk)
14
14
  raise ArgumentError, "missing end_trigger(s)" if end_triggers.empty?
15
15
 
16
- ExAequo::Base::EnumerableHelper.reduce_until_with_trigger(self, initial:, end_triggers:, &blk)
16
+ ExAequo::Base::Enumerable::EnumerableHelper.reduce_until_with_trigger(self, initial:, end_triggers:, &blk)
17
17
  end
18
18
 
19
19
  def reduce_while(initial, *end_triggers, &blk)
20
20
  if end_triggers.empty?
21
- ExAequo::Base::EnumerableHelper.reduce_while_simple(self, initial:, &blk)
21
+ ExAequo::Base::Enumerable::EnumerableHelper.reduce_while_simple(self, initial:, &blk)
22
22
  else
23
- ExAequo::Base::EnumerableHelper.reduce_while_with_trigger(self, initial:, end_triggers:, &blk)
23
+ ExAequo::Base::Enumerable::EnumerableHelper.reduce_while_with_trigger(self, initial:, end_triggers:, &blk)
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ class Hash
29
+ include ExAequo::Base::Enumerable::Hash
30
+ end
27
31
  # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ExAequo
4
4
  module Base
5
- VERSION = '0.1.10'
5
+ VERSION = '0.1.12'
6
6
  end
7
7
  end
8
8
  # SPDX-License-Identifier: AGPL-3.0-or-later
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ex_aequo_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -52,6 +52,9 @@ files:
52
52
  - lib/ex_aequo/base/colorize/colorizer.rb
53
53
  - lib/ex_aequo/base/constants.rb
54
54
  - lib/ex_aequo/base/enumerable.rb
55
+ - lib/ex_aequo/base/enumerable/array.rb
56
+ - lib/ex_aequo/base/enumerable/hash.rb
57
+ - lib/ex_aequo/base/enumerable/helper.rb
55
58
  - lib/ex_aequo/base/enumerable_helper.rb
56
59
  - lib/ex_aequo/base/fn.rb
57
60
  - lib/ex_aequo/base/fn/all.rb