with_ease 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +5 -0
- data/lib/with_ease/all.rb +14 -0
- data/lib/with_ease/array_to_proc.rb +8 -0
- data/lib/with_ease/constructor_functions.rb +10 -0
- data/lib/with_ease/iterator.rb +19 -2
- data/lib/with_ease/open_struct/hash_api.rb +24 -8
- data/lib/with_ease/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44fc03afd4f77bdedbf359da249bb22cf3c80f9eef3f3cd7e24f90287a88536e
|
4
|
+
data.tar.gz: 0002a8ed601d3a61917efdfee29ffe7c2a17b48a476bd3e832c85c42c0b242f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5c2c94c3f0610529fcdb0b570bbd44a19ca6cc9c0fbcbf9b0a0ed27263c21adf30b1c7c6509bcdc633e2bb893c2f900eae5a09bc9b3011c98a075067999c232
|
7
|
+
data.tar.gz: 1f283686e92f306c47b13f94394ad359779342f7d31f4aa7deff37d323ba22bc2ce07d01c88ec423d14657141c894a53a9c25f89d52a11198e5e13ecafe71766
|
data/README.md
CHANGED
@@ -51,6 +51,11 @@ Nothing you cannot do with `Enumerator::Lazy` but so much simpler again.
|
|
51
51
|
|
52
52
|
[c.f for details](speculations/iterator.md)
|
53
53
|
|
54
|
+
#### Extend the `&:<method>` cludge from symbols to arrays with `Array#.to_proc`
|
55
|
+
|
56
|
+
My philosophy on this, is either use both or hate both
|
57
|
+
|
58
|
+
[c.f for details](speculations/array_to_proc.md)
|
54
59
|
|
55
60
|
## Quick Start
|
56
61
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'array_to_proc'
|
4
|
+
require_relative 'closed_struct'
|
5
|
+
require_relative 'forward'
|
6
|
+
require_relative 'iterator'
|
7
|
+
require_relative 'open_struct'
|
8
|
+
|
9
|
+
ClosedStruct = WithEase::ClosedStruct
|
10
|
+
Forward = WithEase::Forward
|
11
|
+
Iterator = WithEase::Iterator
|
12
|
+
|
13
|
+
require_relative 'constructor_functions'
|
14
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'closed_struct'
|
4
|
+
require_relative 'iterator'
|
5
|
+
require_relative 'open_struct'
|
6
|
+
|
7
|
+
def ClosedStruct(**k) = WithEase::ClosedStruct.new(**k)
|
8
|
+
def Iterator(init, &blk) = WithEase::Iterator.new(init, &blk)
|
9
|
+
def OpenStruct(**k) = OpenStruct.new(**k)
|
10
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/with_ease/iterator.rb
CHANGED
@@ -6,7 +6,10 @@ module WithEase
|
|
6
6
|
|
7
7
|
attr_reader :advancer, :value
|
8
8
|
|
9
|
-
def advance = drop
|
9
|
+
def advance = drop
|
10
|
+
def advance_fn = -> { drop }
|
11
|
+
|
12
|
+
def call = advance
|
10
13
|
|
11
14
|
def drop(n=1)
|
12
15
|
n.times do
|
@@ -16,14 +19,28 @@ module WithEase
|
|
16
19
|
end
|
17
20
|
def drop_fn = -> (n=1) { drop n }
|
18
21
|
|
22
|
+
def drop_while(&blk)
|
23
|
+
loop do
|
24
|
+
return self unless blk.(value)
|
25
|
+
advance
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def map(&blk)
|
30
|
+
lazy.map(&blk)
|
31
|
+
end
|
19
32
|
|
20
33
|
def each
|
21
34
|
loop do
|
22
35
|
yield value
|
23
|
-
|
36
|
+
advance
|
24
37
|
end
|
25
38
|
end
|
39
|
+
|
26
40
|
def take_fn = -> (n) { take n }
|
41
|
+
def take_while_fn = -> (&blk) { take_while(&blk) }
|
42
|
+
|
43
|
+
def to_proc = ->(*) { value }
|
27
44
|
|
28
45
|
private
|
29
46
|
def initialize(value, &advancer)
|
@@ -16,15 +16,18 @@ module WithEase
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def update(
|
19
|
+
def update(*positionals, **keys, &blk)
|
20
20
|
if blk
|
21
|
-
return _update_with_blk(
|
21
|
+
return _update_with_blk(*positionals, **keys, &blk)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
case positionals
|
25
|
+
in []
|
26
|
+
_update(keys)
|
27
|
+
in [hash_like]
|
25
28
|
_update(hash_like.to_h.merge(**keys))
|
26
29
|
else
|
27
|
-
|
30
|
+
raise ArgumentError, "must not provide more than one postional argument"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -47,10 +50,23 @@ module WithEase
|
|
47
50
|
self
|
48
51
|
end
|
49
52
|
|
50
|
-
def _update_with_blk(
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
def _update_with_blk(*positionals, **keys, &blk)
|
54
|
+
case positionals
|
55
|
+
in []
|
56
|
+
new_hash = to_h.update(**keys, &blk)
|
57
|
+
_update(new_hash)
|
58
|
+
in [key]
|
59
|
+
if keys.has_key?(:default)
|
60
|
+
value = fetch(key, keys.delete(:default))
|
61
|
+
raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
|
62
|
+
_update(key => blk.(value))
|
63
|
+
else
|
64
|
+
value = fetch(key)
|
65
|
+
raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
|
66
|
+
_update(key => blk.(value))
|
67
|
+
end
|
68
|
+
in [_, _, *]
|
69
|
+
end
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
data/lib/with_ease/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: with_ease
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -34,9 +34,12 @@ files:
|
|
34
34
|
- LICENSE
|
35
35
|
- README.md
|
36
36
|
- lib/with_ease.rb
|
37
|
+
- lib/with_ease/all.rb
|
38
|
+
- lib/with_ease/array_to_proc.rb
|
37
39
|
- lib/with_ease/base.rb
|
38
40
|
- lib/with_ease/closed_struct.rb
|
39
41
|
- lib/with_ease/closed_struct/hash_api.rb
|
42
|
+
- lib/with_ease/constructor_functions.rb
|
40
43
|
- lib/with_ease/forward.rb
|
41
44
|
- lib/with_ease/import_base.rb
|
42
45
|
- lib/with_ease/iterator.rb
|