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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b82599593f37f0f889da475eff808db8fb46259754cd245d11ea842f6e454325
4
- data.tar.gz: 3bf87be2c1b028d522205597c7d952a055bab0907ccc8f2d805ac40902a148ba
3
+ metadata.gz: 44fc03afd4f77bdedbf359da249bb22cf3c80f9eef3f3cd7e24f90287a88536e
4
+ data.tar.gz: 0002a8ed601d3a61917efdfee29ffe7c2a17b48a476bd3e832c85c42c0b242f7
5
5
  SHA512:
6
- metadata.gz: ab419bec4a95ac73a27eed1746a9c231d6c381f318449a92fdba9b77be68a8ebf42a94c855a20fcc627e11f8415f7a5889116e50fb4f1c1d2ae517018d9b5abe
7
- data.tar.gz: aea48838989fd9360f3054eea73c7aee0d5968ab43089bb612e2342656b30e81deecb530cc4ebeac2cae390cdb2111e5949c52c7cf3a8e3f1cfe50439a7028ad
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,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Array
4
+ def to_proc
5
+ -> { it.send(*self) }
6
+ end
7
+ end
8
+ # 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
@@ -6,7 +6,10 @@ module WithEase
6
6
 
7
7
  attr_reader :advancer, :value
8
8
 
9
- def advance = drop(1)
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
- drop
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(hash_like=nil, **keys, &blk)
19
+ def update(*positionals, **keys, &blk)
20
20
  if blk
21
- return _update_with_blk(hash_like, **keys, &blk)
21
+ return _update_with_blk(*positionals, **keys, &blk)
22
22
  end
23
23
 
24
- if hash_like
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
- _update(keys)
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(key, **keys, &blk)
51
- raise ArgumentError, "no **keys arguments allowed in block form" unless keys.empty?
52
- value = fetch(key)
53
- _update(key => blk.(value))
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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WithEase
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  # SPDX-License-Identifier: AGPL-3.0-or-later
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.1
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