ex_aequo_base 0.1.5 → 0.1.6

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: 24a260aad0b858a285db2f96eccff1885c3755e12eed40c61a01d4100ecc40ed
4
- data.tar.gz: 961b6557e5002df0ee9993399de00f4705ecf55561b048e8ef9c5927c924030b
3
+ metadata.gz: 651fee9239497761fb48b5794e89687a1789de5aefd5d463527cf336b36c5f6d
4
+ data.tar.gz: b191bce7fcd36aa4820557fc3cc45bdbe9719b91e035328a9db6566183538ab6
5
5
  SHA512:
6
- metadata.gz: 7ba6c445f2dd6bfa21b20fd7e4bc5b83ce57ebc1b72c62049aad348f30ea36f32dc8e016bddf9cef180b29541ef900837124fb91a10b7e8364bb742e06dee4a1
7
- data.tar.gz: d34123cb7cdf68a20195a4d95a408d30922ec129ab463d894360fecf76574f354bcb8f96c8c909882a09de50168a84696a164db7b8244f5e4d5b97c4899399f3
6
+ metadata.gz: ca06e3932d06661ed25f7dc43ea57fd5edb47ed21a4aed9bbabd55e66c74f46546e20ce833f614244d8ad2a10a3bbc1aed51a658362cf0b19e3a12d46de4e44c
7
+ data.tar.gz: c27d73f78cbbc1820b9e55a66ba9115e7717006135e9d57148831060e37fe56a272c103e7cd6a986728fd87f393fa91c3facdbe4f0980d3d544fa115c70a2369
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  require_relative 'colorize'
3
+ require_relative 'enumerable'
4
+ require_relative 'fn'
3
5
  require_relative 'kernel'
4
6
  require_relative 'open_struct'
7
+ require_relative 'regexp'
5
8
  # require_relative 'match_data'
6
9
  Colorize = ExAequo::Base::Colorize
7
10
  # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'enumerable_helper'
4
+ module Enumerable
5
+ def find_value(&blk)
6
+ each do
7
+ val = blk.(it)
8
+ return val if val
9
+ end
10
+ nil
11
+ end
12
+
13
+ def reduce_until(initial, *end_triggers, &blk)
14
+ raise ArgumentError, "missing end_trigger(s)" if end_triggers.empty?
15
+
16
+ ExAequo::Base::EnumerableHelper.reduce_until_with_trigger(self, initial:, end_triggers:, &blk)
17
+ end
18
+
19
+ def reduce_while(initial, *end_triggers, &blk)
20
+ if end_triggers.empty?
21
+ ExAequo::Base::EnumerableHelper.reduce_while_simple(self, initial:, &blk)
22
+ else
23
+ ExAequo::Base::EnumerableHelper.reduce_while_with_trigger(self, initial:, end_triggers:, &blk)
24
+ end
25
+ end
26
+ end
27
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fn'
4
+ module ExAequo
5
+ module Base
6
+ module EnumerableHelper extend self
7
+ def reduce_until_with_trigger(enum, initial:, end_triggers:, &blk)
8
+ f = Fn.mk_fun_pipeline(end_triggers)
9
+ enum.each do
10
+ return initial if f.(initial)
11
+ initial = blk.(initial, it)
12
+ end
13
+ initial
14
+ end
15
+
16
+ def reduce_while_simple(enum, initial:, &blk)
17
+ enum.each do
18
+ val = blk.(initial, it)
19
+ if val
20
+ initial = val
21
+ else
22
+ return initial
23
+ end
24
+ end
25
+ initial
26
+ end
27
+
28
+ def reduce_while_with_trigger(enum, initial:, end_triggers:, &blk)
29
+ f = Fn.mk_fun_pipeline(end_triggers)
30
+ enum.each do
31
+ val = blk.(initial, it)
32
+ # p(val:, f: f.(val))
33
+ if f.(val)
34
+ initial = val
35
+ else
36
+ return initial
37
+ end
38
+ end
39
+ initial
40
+ end
41
+ end
42
+ end
43
+ end
44
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'to_proc'
4
+ module ExAequo
5
+ module Base
6
+ module Fn extend self
7
+ def _not = -> { !it }
8
+
9
+ Operators = {
10
+ '!' => _not,
11
+ }
12
+
13
+
14
+ def mk_fun(fn_desc)
15
+ case fn_desc
16
+ in String
17
+ mk_op(fn_desc)
18
+ in Symbol
19
+ -> { it.send(fn_desc) }
20
+ in Array
21
+ -> { it.send(*fn_desc) }
22
+ in _
23
+ fn_desc.to_proc
24
+ end
25
+ # TODO: Allow for other fn_desc then Array and Symbol
26
+ end
27
+
28
+ def mk_fun_pipeline(fn_descs)
29
+ fns = fn_descs.map { mk_fun it }
30
+ -> do
31
+ fns.inject(it) { |acc, f| f.(acc) }
32
+ end
33
+ end
34
+
35
+ def mk_op(op)
36
+ Operators.fetch(op) { raise ArgumentError, "undefined operator #{op.inspect}" }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'to_proc/regexp'
4
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FalseClass
4
+ def to_proc
5
+ ->(*) { false }
6
+ end
7
+ end
8
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class NilClass
4
+ def to_proc
5
+ ->(*) { nil }
6
+ end
7
+ end
8
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ class Regexp
3
+ def to_proc
4
+ -> { match(it) }
5
+ end
6
+ end
7
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TrueClass
4
+ def to_proc
5
+ ->(*) { true }
6
+ end
7
+ end
8
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'kernel'
4
+ require_subdir __FILE__
5
+ # 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.5'
5
+ VERSION = '0.1.6'
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -65,10 +65,19 @@ files:
65
65
  - lib/ex_aequo/base/colorize/color_definitions.rb
66
66
  - lib/ex_aequo/base/colorize/colorizer.rb
67
67
  - lib/ex_aequo/base/constants.rb
68
+ - lib/ex_aequo/base/enumerable.rb
69
+ - lib/ex_aequo/base/enumerable_helper.rb
70
+ - lib/ex_aequo/base/fn.rb
68
71
  - lib/ex_aequo/base/kernel.rb
69
72
  - lib/ex_aequo/base/match_data.rb
70
73
  - lib/ex_aequo/base/open_struct.rb
74
+ - lib/ex_aequo/base/regexp.rb
71
75
  - lib/ex_aequo/base/string/colorize.rb
76
+ - lib/ex_aequo/base/to_proc.rb
77
+ - lib/ex_aequo/base/to_proc/false_class.rb
78
+ - lib/ex_aequo/base/to_proc/nil_class.rb
79
+ - lib/ex_aequo/base/to_proc/regexp.rb
80
+ - lib/ex_aequo/base/to_proc/true_class.rb
72
81
  - lib/ex_aequo/base/version.rb
73
82
  homepage: https://codeberg.org/lab419/rb_ex_aequo_base
74
83
  licenses: