iterate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 84c6a43c71aca508648977a39ea6edd65558c23a
4
+ data.tar.gz: 439eb2886aea13f2f99deeb0be37840b66a5ff2f
5
+ SHA512:
6
+ metadata.gz: e05459a5285510ca07b053df8029d5d01f5d6cb2a8df3b29423149bd10ac33b0eb1f837e1e312dc54cded19e947cb32ed813822fecab7a602257e15c1de6d33f
7
+ data.tar.gz: fbef53f763d0cebdebba8e83175cb8ff8f7b0e9fbdeba3b325543242c2a250c2fa530cc8bcde5c778864a9afb7cd8715eb6b4cda0359ce7921bbdef4cc58621e
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ /pkg
@@ -0,0 +1,20 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ script: bundle exec ruby spec/iterate_spec.rb
5
+
6
+ rvm:
7
+ - 2.3.0
8
+ - 2.2
9
+ - 2.1
10
+ - 2.0
11
+ - ruby-head
12
+ - rbx-2
13
+ - jruby-head
14
+ - jruby-9000
15
+
16
+ cache:
17
+ - bundler
18
+
19
+ # matrix:
20
+ # fast_finish: true
@@ -0,0 +1,5 @@
1
+ ## CHANGELOG
2
+
3
+ ### 1.0.0
4
+
5
+ * Moved from zucker gem into its own gem
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'minitest'
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010-2016 Jan Lelis, mail@janlelis.de
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # Kernel#iterate [![[version]](https://badge.fury.io/rb/iterate.svg)](http://badge.fury.io/rb/iterate) [![[travis]](https://travis-ci.org/janlelis/iterate.png)](https://travis-ci.org/janlelis/iterate)
2
+
3
+ Iterate over one or more collections. It feels like an `.each` implemented as a control structure. It also makes it easier to iterate over multiple objects.
4
+
5
+
6
+ ## Usage
7
+
8
+ ```ruby
9
+ iterate [1,2], [3,4,5] do |e, f|
10
+ puts "#{e},#{f}"
11
+ end
12
+
13
+ # 1,3
14
+ # 2,4
15
+ # ,5
16
+ ```
17
+
18
+
19
+ ## Setup
20
+
21
+ Add to your `Gemfile`:
22
+
23
+ ```ruby
24
+ gem 'iterate'
25
+ ```
26
+
27
+
28
+ ## MIT License
29
+
30
+ Copyright (C) 2010-2016 Jan Lelis <http://janlelis.com>. Released under the MIT license.
@@ -0,0 +1,30 @@
1
+ # # #
2
+ # Get gemspec info
3
+
4
+ gemspec_file = Dir['*.gemspec'].first
5
+ gemspec = eval File.read(gemspec_file), binding, gemspec_file
6
+ info = "#{gemspec.name} | #{gemspec.version} | " \
7
+ "#{gemspec.runtime_dependencies.size} dependencies | " \
8
+ "#{gemspec.files.size} files"
9
+
10
+
11
+ # # #
12
+ # Gem build and install task
13
+
14
+ desc info
15
+ task :gem do
16
+ puts info + "\n\n"
17
+ print " "; sh "gem build #{gemspec_file}"
18
+ FileUtils.mkdir_p 'pkg'
19
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
20
+ puts; sh %{gem install --no-document pkg/#{gemspec.name}-#{gemspec.version}.gem}
21
+ end
22
+
23
+
24
+ # # #
25
+ # Start an IRB session with the gem loaded
26
+
27
+ desc "#{gemspec.name} | IRB"
28
+ task :irb do
29
+ sh "irb -I ./lib -r #{gemspec.name.gsub '-','/'}"
30
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.dirname(__FILE__) + "/lib/iterate/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "iterate"
7
+ gem.version = Iterate::VERSION
8
+ gem.summary = "Iterate over one or more collections."
9
+ gem.description = "Iterate over one or more collections. It feels like an .each implemented as a control structure. It also makes it easier to iterate over multiple objects."
10
+ gem.authors = ["Jan Lelis"]
11
+ gem.email = ["mail@janlelis.de"]
12
+ gem.homepage = "https://github.com/janlelis/iterate"
13
+ gem.license = "MIT"
14
+
15
+ gem.files = Dir["{**/}{.*,*}"].select{ |path| File.file?(path) && path !~ /^pkg/ }
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.required_ruby_version = "~> 2.0"
21
+ end
@@ -0,0 +1,17 @@
1
+ require_relative "iterate/version"
2
+
3
+ module Kernel
4
+ private
5
+
6
+ def iterate(*iteratables)
7
+ raise ArgumentError, "wrong number of arguments (0)" if iteratables.empty?
8
+ first, rest = iteratables[0], iteratables[1..-1]
9
+ if rest.empty?
10
+ block_given? ? first.map{ |e| yield e } : first.map.to_enum
11
+ else
12
+ padding = iteratables.max_by(&:size).size - first.size
13
+ iter = (first.to_a + [nil]*padding).zip(*rest)
14
+ block_given? ? iter.map{|es| yield(*es) } : iter.map.to_enum
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Iterate
2
+ VERSION = "1.0.0".freeze
3
+ end
4
+
@@ -0,0 +1,67 @@
1
+ require_relative "../lib/iterate"
2
+ require "minitest/autorun"
3
+
4
+ describe 'Kernel#iterate' do
5
+ it 'should behave like Enumerable#each for a single argument' do
6
+ array = [1, 2, 3]
7
+ res_each = []
8
+ res_iterate = []
9
+
10
+ array.each do |ele|
11
+ res_each << ele
12
+ end
13
+
14
+ iterate array do |ele|
15
+ res_iterate << ele
16
+ end
17
+
18
+ assert_equal res_each, res_iterate
19
+ end
20
+
21
+ it 'should pass the right params to the block' do
22
+ a = [1, 2, 3]
23
+ b = %w[a b c d]
24
+ res_a_b = []
25
+ res_b_a = []
26
+
27
+ iterate a, b do |e, f|
28
+ res_a_b << [e, f]
29
+ end
30
+
31
+ assert_equal [
32
+ [1, 'a'],
33
+ [2, 'b'],
34
+ [3, 'c'],
35
+ [nil, 'd'],
36
+ ], res_a_b
37
+
38
+ iterate b, a do |e, f|
39
+ res_b_a << [e, f]
40
+ end
41
+
42
+ assert_equal [
43
+ ['a', 1],
44
+ ['b', 2],
45
+ ['c', 3],
46
+ ['d', nil],
47
+ ], res_b_a
48
+ end
49
+
50
+ it 'should return enumerators if no block is applied' do
51
+ res = iterate [1, 2, 3], %w[a b c d]
52
+
53
+ assert_kind_of Enumerator, res
54
+ assert_equal [
55
+ [1,'a'],
56
+ [2,'b'],
57
+ [3,'c'],
58
+ [nil, 'd']
59
+ ], res.to_a
60
+ end
61
+
62
+ it 'raises an ArgumentError for no arguments' do
63
+ assert_raises ArgumentError do
64
+ iterate
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iterate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jan Lelis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Iterate over one or more collections. It feels like an .each implemented
14
+ as a control structure. It also makes it easier to iterate over multiple objects.
15
+ email:
16
+ - mail@janlelis.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - Gemfile
25
+ - MIT-LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - iterate.gemspec
29
+ - lib/iterate.rb
30
+ - lib/iterate/version.rb
31
+ - spec/iterate_spec.rb
32
+ homepage: https://github.com/janlelis/iterate
33
+ licenses:
34
+ - MIT
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '2.0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.5.1
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Iterate over one or more collections.
56
+ test_files:
57
+ - spec/iterate_spec.rb