ex_aequo_base 0.1.5 → 0.1.7

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: 924bbe0dc0445b557f63850ebfd7650b3f41216d52789a48e0701ebe6afe7b3a
4
+ data.tar.gz: ec3e3ff23194b4d3de28190ca34cfba950460e1df1b778421733ecca6f2b2327
5
5
  SHA512:
6
- metadata.gz: 7ba6c445f2dd6bfa21b20fd7e4bc5b83ce57ebc1b72c62049aad348f30ea36f32dc8e016bddf9cef180b29541ef900837124fb91a10b7e8364bb742e06dee4a1
7
- data.tar.gz: d34123cb7cdf68a20195a4d95a408d30922ec129ab463d894360fecf76574f354bcb8f96c8c909882a09de50168a84696a164db7b8244f5e4d5b97c4899399f3
6
+ metadata.gz: 543c0c2a5159d23e0ceab290888bad113373c38c3b28c5c197e7a4a4ab10dfc7ee35a2b4034b7a442c4e88a8a0623654612b8130cb05ab26f22ba13db68e95ba
7
+ data.tar.gz: e0f75b5c0e3479d0d876236c35e481ac8d74e32bb14813d73532b72c63cfa79905c51945ba79f0100a04e1703ceb11f2b027a6618284fdb7cd3eee9b77848ed0
@@ -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,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../fn'
4
+ require_relative 'curry'
5
+
6
+ Fn = ExAequo::Base::Fn
7
+ Placeholder = Fn::Placeholder
8
+
9
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers'
4
+ module ExAequo
5
+ module Base
6
+ module Fn extend self
7
+ extend Forwarder
8
+ forward_all :curry, to: Helpers
9
+ end
10
+ end
11
+ end
12
+ # SPDX-License-Identifier: AGPL-3.0-or-later
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ExAequo
4
+ module Base
5
+ module Fn
6
+ Placeholder = BasicObject.new
7
+
8
+ module Helpers extend self
9
+ def curry(rcv, *positionals, **keywords, &blk)
10
+ return _send_curry(*positionals, **keywords, &blk) if rcv == Placeholder
11
+
12
+ _send_to(rcv, *positionals, **keywords, &blk)
13
+ end
14
+
15
+ private
16
+ def _make_actual_params(positionals, args, keywords, kwds, offset:)
17
+ as = []
18
+ ks = {}
19
+ n = 0
20
+
21
+ positionals.each do
22
+ if it == Placeholder
23
+ as << args[n]
24
+ n += 1
25
+ else
26
+ as << it
27
+ end
28
+ end
29
+
30
+ keywords.each do |k, v|
31
+ if v == Placeholder
32
+ ks[k] = args[n]
33
+ n += 1
34
+ end
35
+ end
36
+ as += Array(args[positionals.length-offset..])
37
+ [as, keywords.merge(ks).merge(kwds)]
38
+ end
39
+
40
+ def _send_curry(*positionals, **keywords, &b)
41
+ -> (rcv, *args, **kwds, &blk) do
42
+ _make_actual_params(positionals, args, keywords, kwds, offset: 1) => actual_pos, actual_kwds
43
+ rcv.send(*actual_pos, **actual_kwds, &(blk || b))
44
+ end
45
+ end
46
+
47
+ def _send_to(rcv, *positionals, **keywords, &b)
48
+ -> (*args, **kwds, &blk) do
49
+ _make_actual_params(positionals, args, keywords, kwds, offset: 0) => actual_pos, actual_kwds
50
+ rcv.send(*actual_pos, **actual_kwds, &(blk || b))
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ # 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.7'
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.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
@@ -65,10 +65,22 @@ 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
71
+ - lib/ex_aequo/base/fn/all.rb
72
+ - lib/ex_aequo/base/fn/curry.rb
73
+ - lib/ex_aequo/base/fn/helpers.rb
68
74
  - lib/ex_aequo/base/kernel.rb
69
75
  - lib/ex_aequo/base/match_data.rb
70
76
  - lib/ex_aequo/base/open_struct.rb
77
+ - lib/ex_aequo/base/regexp.rb
71
78
  - lib/ex_aequo/base/string/colorize.rb
79
+ - lib/ex_aequo/base/to_proc.rb
80
+ - lib/ex_aequo/base/to_proc/false_class.rb
81
+ - lib/ex_aequo/base/to_proc/nil_class.rb
82
+ - lib/ex_aequo/base/to_proc/regexp.rb
83
+ - lib/ex_aequo/base/to_proc/true_class.rb
72
84
  - lib/ex_aequo/base/version.rb
73
85
  homepage: https://codeberg.org/lab419/rb_ex_aequo_base
74
86
  licenses:
@@ -88,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
100
  - !ruby/object:Gem::Version
89
101
  version: '0'
90
102
  requirements: []
91
- rubygems_version: 3.6.8
103
+ rubygems_version: 3.6.9
92
104
  specification_version: 4
93
105
  summary: The code I use all the time
94
106
  test_files: []