ex_aequo_base 0.1.4 → 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: 2f42430967e4c2f9e06b956df55783e74a92a1e820d226b580517f21f50c00e2
4
- data.tar.gz: fb27b96a0dcabf3730527c162013114a465c00ac4a369595c25ac17fc9d032ad
3
+ metadata.gz: 651fee9239497761fb48b5794e89687a1789de5aefd5d463527cf336b36c5f6d
4
+ data.tar.gz: b191bce7fcd36aa4820557fc3cc45bdbe9719b91e035328a9db6566183538ab6
5
5
  SHA512:
6
- metadata.gz: 84104dce64e79d0fe8945d1aeaac2f63bbb14329933eb4e9f84aefbfae68f2b842c9c0de5c82dca1c1c1cfddc3d2060dd532f7d03001efeffe5d3625b15b8a23
7
- data.tar.gz: ce17b03ae58f71e3b0d9c2c45d9c7e55a32b1ad7788f1c31163f4fd263879c340a1a6558495026060caf950dcf0a394eb43ccef3b1112f1164165e8b3a241343
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
@@ -3,14 +3,13 @@
3
3
  require_relative 'constants'
4
4
  module ExAequo::Base::KernelHelper extend self
5
5
 
6
- def require_subdir(file, descend:, &blk)
7
-
8
- raise ArgumentError, "must not provide positional file parameter #{file.inspect} and a block" if file && blk
9
- raise ArgumentError, "must provide file or block" unless file || blk
10
- if file
11
- req_subdir_file(file, descend:)
12
- else
6
+ def require_subdir(*files, descend:, &blk)
7
+ raise ArgumentError, "must not provide positional file parameter #{files} and a block" if !files.empty? && blk
8
+ raise ArgumentError, "must provide file or block" unless !files.empty? || blk
9
+ if files.empty?
13
10
  req_subdir_blk(descend:, &blk)
11
+ else
12
+ req_subdir_file(File.join(files), descend:)
14
13
  end
15
14
  end
16
15
 
@@ -46,8 +45,8 @@ module ExAequo::Base::KernelHelper extend self
46
45
  end
47
46
 
48
47
  module Kernel
49
- def require_subdir(file=nil, descend: false, &blk)
50
- ExAequo::Base::KernelHelper.require_subdir(file, descend:, &blk)
48
+ def require_subdir(*files, descend: false, &blk)
49
+ ExAequo::Base::KernelHelper.require_subdir(*files, descend:, &blk)
51
50
  end
52
51
  end
53
52
  # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -6,6 +6,12 @@ class OpenStruct
6
6
  extend Forwarder
7
7
  forward_all :deconstruct_keys, :empty?, :fetch, :has_key?, to: :to_h
8
8
 
9
+ def self.to_proc
10
+ -> hashy do
11
+ new hashy
12
+ end
13
+ end
14
+
9
15
  def update(hashy)
10
16
  hashy.to_h.each do |k, v|
11
17
  self[k] = v
@@ -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.4'
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.4
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: