mug 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 330eebe01439970eeb98b02f25580aa4b33335c3a3d7abe0994c378c8171d5eb
4
- data.tar.gz: aaa14057580d8ed7a51a575c9eb8820de6a9507724ad953791e596a3a96fd3d7
3
+ metadata.gz: 3e14ce5838a2c49e7ede7dba94a8aa1b330efba9ecec52261d611985d30bd47d
4
+ data.tar.gz: 89a7d9d6ddb730004f062f625d81301f1d9271759b8c5ab717e1a42407981b44
5
5
  SHA512:
6
- metadata.gz: ea3615b7990f7bfd2505985c3ae8ecea789390904fb4a136973c3e211c764a32861c4d2dfb8b1691b4c64ac09fcc184b902a612f6d988cab61c0137724d019d2
7
- data.tar.gz: 295e43e6f35e73a2b7cf2fe79dc99466ddd4f0624c1c83f400e5bdbe6665a3ff99559a367bcf9ea3e8d771689c6c0161fc1d533988baceb255212f3520d96166
6
+ metadata.gz: 5f3da00b7a7b2ba58dfcd8b5efaae57ccd035c9e36d90182a13204578089e071d0a6a614c031585eaf81f8f9bd4c06adbaf8d04a52159ad37951b396c0b73c08
7
+ data.tar.gz: 71c1e2a2cf4c87b0b4a4e13f837c36042c374b0b50a6d210d09b838b0470e87310765c57bee9ad02b711d4bc1287cd5856b0ef26ee2c2a2fbcee30a12f10e965
data/lib/mug.rb CHANGED
@@ -11,7 +11,10 @@ require_relative 'mug/array/to_proc'
11
11
  require_relative 'mug/bool'
12
12
  require_relative 'mug/bittest'
13
13
  require_relative 'mug/clamp'
14
- require_relative 'mug/enumerable'
14
+ require_relative 'mug/enumerable/any-and-all'
15
+ require_relative 'mug/enumerable/chain'
16
+ require_relative 'mug/enumerable/counts'
17
+ require_relative 'mug/enumerable/hash-like'
15
18
  require_relative 'mug/fragile-method-chain'
16
19
  require_relative 'mug/hash/map'
17
20
  require_relative 'mug/hash/merge'
@@ -1,5 +1,6 @@
1
1
 
2
2
  require_relative 'enumerable/any-and-all'
3
+ require_relative 'enumerable/chain'
3
4
  require_relative 'enumerable/counts'
4
5
  require_relative 'enumerable/hash-like'
5
6
 
@@ -0,0 +1,46 @@
1
+
2
+ module Enumerable
3
+
4
+ class <<self
5
+ #
6
+ # Invokes a block once for every element in a sequence of
7
+ # Enumerables.
8
+ #
9
+ def chain *enums
10
+ return enum_for(:chain, *enums) unless block_given?
11
+ enums.each do |enum|
12
+ enum.each {|*args| yield *args }
13
+ end
14
+ end
15
+ end
16
+
17
+ #
18
+ # Creates a chain of Enumerables following this one, and
19
+ # invokes a block once for each element of each Enumerable.
20
+ #
21
+ def chain *enums
22
+ return enum_for(:chain, *enums) unless block_given?
23
+ [self, *enums].each do |enum|
24
+ enum.each {|*args| yield *args }
25
+ end
26
+ nil
27
+ end
28
+
29
+ end
30
+
31
+ =begin
32
+ Copyright (c) 2018, Matthew Kerwin <matthew@kerwin.net.au>
33
+
34
+ Permission to use, copy, modify, and/or distribute this software for any
35
+ purpose with or without fee is hereby granted, provided that the above
36
+ copyright notice and this permission notice appear in all copies.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
39
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
40
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
41
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
42
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
43
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
44
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45
+ =end
46
+
@@ -0,0 +1,80 @@
1
+ require 'test/unit'
2
+ $VERBOSE = true
3
+
4
+ require_relative '../lib/mug/enumerable/chain'
5
+ class Test_enumerable_chain < Test::Unit::TestCase
6
+ def test_chain
7
+ a = [1, 2, 3, 4].each_with_index
8
+ b = [5, 6].each_with_index
9
+ c = [7, 8].each_with_index
10
+ expect = [
11
+ [1,0], [2,1], [3,2], [4,3],
12
+ [5,0], [6,1],
13
+ [7,0], [8,1],
14
+ ]
15
+
16
+ result = []
17
+ a.chain(b, c) do |*a|
18
+ result << a
19
+ end
20
+
21
+ assert_equal( expect, result )
22
+ end
23
+
24
+ def test_chain__noblock
25
+ a = [1, 2, 3, 4].each_with_index
26
+ b = [5, 6].each_with_index
27
+ c = [7, 8].each_with_index
28
+ expect = [
29
+ [1,0], [2,1], [3,2], [4,3],
30
+ [5,0], [6,1],
31
+ [7,0], [8,1],
32
+ ]
33
+
34
+ enum = a.chain(b, c)
35
+ assert_kind_of( Enumerator, enum )
36
+
37
+ result = []
38
+ enum.each do |*a|
39
+ result << a
40
+ end
41
+
42
+ assert_equal( expect, result )
43
+ end
44
+
45
+ def test_chain0
46
+ a = [1, 2, 3, 4].each_with_index
47
+ b = [5, 6, 7, 8].each_with_index
48
+ expect = [
49
+ [1,0], [2,1], [3,2], [4,3],
50
+ [5,0], [6,1], [7,2], [8,3],
51
+ ]
52
+
53
+ result = []
54
+ Enumerable.chain(a, b) do |*a|
55
+ result << a
56
+ end
57
+
58
+ assert_equal( expect, result )
59
+ end
60
+
61
+ def test_chain0__noblock
62
+ a = [1, 2, 3, 4].each_with_index
63
+ b = [5, 6, 7, 8].each_with_index
64
+ expect = [
65
+ [1,0], [2,1], [3,2], [4,3],
66
+ [5,0], [6,1], [7,2], [8,3],
67
+ ]
68
+
69
+ enum = Enumerable.chain(a, b)
70
+ assert_kind_of( Enumerator, enum )
71
+
72
+ result = []
73
+ enum.each do |*a|
74
+ result << a
75
+ end
76
+
77
+ assert_equal( expect, result )
78
+ end
79
+ end
80
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mug
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Kerwin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-02 00:00:00.000000000 Z
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  == MUG: Matty's Ultimate Gem
@@ -40,6 +40,7 @@ files:
40
40
  - lib/mug/counts.rb
41
41
  - lib/mug/enumerable.rb
42
42
  - lib/mug/enumerable/any-and-all.rb
43
+ - lib/mug/enumerable/chain.rb
43
44
  - lib/mug/enumerable/counts.rb
44
45
  - lib/mug/enumerable/hash-like.rb
45
46
  - lib/mug/fragile-method-chain.rb
@@ -83,6 +84,7 @@ files:
83
84
  - test/test-bool.rb
84
85
  - test/test-clamp.rb
85
86
  - test/test-counts.rb
87
+ - test/test-enumerable-chain.rb
86
88
  - test/test-enumerable-hash-like.rb
87
89
  - test/test-fragile-method-chain.rb
88
90
  - test/test-hashmap.rb
@@ -133,6 +135,7 @@ test_files:
133
135
  - test/test-maybe.rb
134
136
  - test/test-hashop.rb
135
137
  - test/test-not.rb
138
+ - test/test-enumerable-chain.rb
136
139
  - test/test-loop-with.rb
137
140
  - test/test-counts.rb
138
141
  - test/test-array-minus.rb