parray 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb3d92437388593f30bd3e15404d7eb1055b5bace2524c144389b593e130a106
4
+ data.tar.gz: 48c07caa643a68ec2fef4c93c1f5da0b90f45e653332f37ec1ce9d9ecde2053c
5
+ SHA512:
6
+ metadata.gz: fdf58ed916bf9cb11ac401841222c879b054fea99bbb14e799c89c805ff46e1071e9d0a658ced97deb723f6a209788a59f9e61b1b15f4cbd7d7ad66f376df45d
7
+ data.tar.gz: cd6b5ad160ce089e543d3d55b4e6cf1cf47db0b834a2acb7b36a4b993bf7f5439752548d34d778e9a93308cde6b2717bc6b7ba95c4d72a37b7fcca0f336a197f
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in parray.gemspec
6
+ gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parray (0.1.0)
5
+ parallel (~> 1.12)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ method_source (0.9.2)
13
+ parallel (1.12.1)
14
+ pry (0.12.2)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ rake (10.5.0)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+
32
+ PLATFORMS
33
+ ruby
34
+
35
+ DEPENDENCIES
36
+ bundler (~> 1.17)
37
+ parray!
38
+ pry
39
+ rake (~> 10.0)
40
+ rspec (~> 3.8)
41
+
42
+ BUNDLED WITH
43
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Nao Minami
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ # PArray
2
+ Convert enumerable objects into **p**arallelized **array**s.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'parray'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install parray
19
+
20
+ ## Usage
21
+
22
+ By using `parallelize`, you can convert enumerable objects into parallelized arrays. In enumerable operations, parallelized arrays use multiple threads to execute each block concurrently. The default size of threads is 2.
23
+
24
+ ```ruby
25
+ [1] pry(main)> include PArray::API
26
+
27
+ [2] pry(main)> a = parallelize([1, 2, 3])
28
+ => #<PArray:0x00007fd786872840 @arr=[1, 2, 3], @in_threads=2>
29
+
30
+ [3] pry(main)> a.map { |i| sleep(rand); p i; i * 2 }
31
+ 2
32
+ 3
33
+ 1
34
+ => [2, 4, 6]
35
+ ```
36
+
37
+ You can also use `PArray.parallelize` to convert enumerable objects.
38
+
39
+ ```ruby
40
+ [1] pry(main)> a = PArray.parallelize([1, 2, 3])
41
+ => #<PArray:0x00007fd7863283a8 @arr=[1, 2, 3], @in_threads=2>
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake true` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/south37/parray.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "parray"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "pry"
10
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ require "parallel"
2
+
3
+ require "parray/api"
4
+ require "parray/error"
5
+ require "parray/version"
6
+
7
+ class PArray
8
+ class << self
9
+ DEFAULT_CONCURRENCY = 2
10
+
11
+ def parallelize(arr, in_threads: DEFAULT_CONCURRENCY)
12
+ PArray.new(arr, in_threads: in_threads)
13
+ end
14
+ end
15
+
16
+ include Enumerable
17
+
18
+ def initialize(arr, in_threads:)
19
+ if !arr.respond_to?(:to_a)
20
+ raise Error.new("#{arr} must respond to `#to_a`!")
21
+ end
22
+ @arr = arr
23
+ @in_threads = in_threads
24
+ end
25
+
26
+ def map(&block)
27
+ Parallel.map(@arr.to_a, in_threads: @in_threads) { |*args| yield *args }
28
+ end
29
+
30
+ def each(&block)
31
+ Parallel.each(@arr.to_a, in_threads: @in_threads) { |*args| yield *args }
32
+ end
33
+
34
+ def to_a
35
+ @arr.to_a
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ class PArray
2
+ module API
3
+ class << self
4
+ def included(klass)
5
+ klass.extend self
6
+ end
7
+ end
8
+
9
+ def parallelize(*args)
10
+ PArray.parallelize(*args)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class PArray
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,3 @@
1
+ class PArray
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "parray/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "parray"
7
+ spec.version = PArray::VERSION
8
+ spec.authors = ["Nao Minami"]
9
+ spec.email = ["south37777@gmail.com"]
10
+
11
+ spec.summary = %q{Convert enumerable objects into parallelized arrays}
12
+ spec.description = %q{Convert enumerable objects into parallelized arrays}
13
+ spec.homepage = "https://github.com/south37/parray"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.8"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_dependency "parallel", "~> 1.12"
30
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parray
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nao Minami
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: parallel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ description: Convert enumerable objects into parallelized arrays
84
+ email:
85
+ - south37777@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/parray.rb
100
+ - lib/parray/api.rb
101
+ - lib/parray/error.rb
102
+ - lib/parray/version.rb
103
+ - parray.gemspec
104
+ homepage: https://github.com/south37/parray
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Convert enumerable objects into parallelized arrays
127
+ test_files: []