tuples 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +49 -0
- data/README.md +70 -0
- data/Rakefile +5 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/lib/tuples.rb +8 -0
- data/lib/tuples/pair.rb +21 -0
- data/lib/tuples/tuple.rb +36 -0
- data/lib/tuples/version.rb +3 -0
- data/tuples.gemspec +26 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7dfcd356f4c8faa253eceffec0148e480fe2653f
|
4
|
+
data.tar.gz: ea9f940b9cd46365f03f5e93ceccf0c1f891b25f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d69145b46dcfbfce82c5a5f137620cf5fa316cbde1048b70cdcc0927709a06d9a70240fef28277c77efc4b4107996a513f12e5b5ac081251eca7fbfa440bc4bb
|
7
|
+
data.tar.gz: 52403cc9cc718ef69af38dd3e133f0e031b19f487f5695494d46f0456cdc249763e5e8520198dde4ca45be576320f725d311124d48ac335a1e7b8520b8771e11
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tuples (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (4.0.5)
|
10
|
+
columnize (= 0.9.0)
|
11
|
+
coderay (1.1.0)
|
12
|
+
columnize (0.9.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
method_source (0.8.2)
|
15
|
+
pry (0.10.1)
|
16
|
+
coderay (~> 1.1.0)
|
17
|
+
method_source (~> 0.8.1)
|
18
|
+
slop (~> 3.4)
|
19
|
+
pry-byebug (3.1.0)
|
20
|
+
byebug (~> 4.0)
|
21
|
+
pry (~> 0.10)
|
22
|
+
rake (10.4.2)
|
23
|
+
rspec (3.2.0)
|
24
|
+
rspec-core (~> 3.2.0)
|
25
|
+
rspec-expectations (~> 3.2.0)
|
26
|
+
rspec-mocks (~> 3.2.0)
|
27
|
+
rspec-collection_matchers (1.1.2)
|
28
|
+
rspec-expectations (>= 2.99.0.beta1)
|
29
|
+
rspec-core (3.2.3)
|
30
|
+
rspec-support (~> 3.2.0)
|
31
|
+
rspec-expectations (3.2.1)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.2.0)
|
34
|
+
rspec-mocks (3.2.1)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.2.0)
|
37
|
+
rspec-support (3.2.2)
|
38
|
+
slop (3.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 1.9)
|
45
|
+
pry-byebug (~> 3.1.0)
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.2.0)
|
48
|
+
rspec-collection_matchers (~> 1.1.2)
|
49
|
+
tuples!
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Tuples
|
2
|
+
|
3
|
+
[ ![Codeship Status for KamilLelonek/ruby-tuples](https://codeship.com/projects/c82b3680-e2e1-0132-cc6e-76e3d81118b5/status?branch=master)](https://codeship.com/projects/81591)
|
4
|
+
|
5
|
+
Ruby implementation for tuples known from functional programming.
|
6
|
+
|
7
|
+
Tuple combines a fixed number of items together so that they can be passed around as a whole. Unlike an array or list, a tuple can hold objects with different types but they are also immutable.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'tuples'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install tuples
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
You are provided with two classes:
|
28
|
+
|
29
|
+
- `Tuple` in general
|
30
|
+
- `Pair` in particular
|
31
|
+
|
32
|
+
The main difference between two of them are that `Tuple` always consist of 2 elements - when initialized with less - the missing ones are filled with `nil`, when initialized with more - an `ArgumentError` is raised.
|
33
|
+
|
34
|
+
You can initialize them in different ways:
|
35
|
+
|
36
|
+
Tuple.new(1, 2)
|
37
|
+
Tuple.new([1, 2])
|
38
|
+
Tuple(1, 2)
|
39
|
+
Tuple([1, 2])
|
40
|
+
Tuple[1, 2]
|
41
|
+
|
42
|
+
depending on which syntax you feel more convenient with.
|
43
|
+
|
44
|
+
Both of the classes have some auxiliary methods:
|
45
|
+
|
46
|
+
- `length` / `arity` - which returns number of values inside tuple
|
47
|
+
- `first` / `last` / `second` (only pair) - which returns a corresponding elements
|
48
|
+
- `[]` that gives you an access to a particular elements
|
49
|
+
|
50
|
+
Tuples are also comparable which means you can compare them, match them in `case` statement or even sort and find them in an array.
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Tests
|
59
|
+
|
60
|
+
To run all tests from `spec` directory execute:
|
61
|
+
|
62
|
+
bundle exec rspec
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it ( https://github.com/[my-github-username]/tuples/fork )
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/tuples.rb
ADDED
data/lib/tuples/pair.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'tuple'
|
2
|
+
|
3
|
+
class Pair < Tuple
|
4
|
+
def initialize(*values)
|
5
|
+
values.flatten.tap do |arguments|
|
6
|
+
raise ArgumentError, 'Pair must contain only two elements' if more_than_two_arguments?(arguments)
|
7
|
+
super(arguments[0], arguments[1])
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :second, :last
|
12
|
+
|
13
|
+
private
|
14
|
+
def more_than_two_arguments?(arguments)
|
15
|
+
arguments.length > 2
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def Pair(*values)
|
20
|
+
Pair.new(*values)
|
21
|
+
end
|
data/lib/tuples/tuple.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class Tuple
|
2
|
+
extend Forwardable
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
def initialize(*values)
|
6
|
+
@values = values.flatten.freeze
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.[](*values)
|
10
|
+
new(*values)
|
11
|
+
end
|
12
|
+
|
13
|
+
def <=>(other)
|
14
|
+
return unless other.kind_of? self.class
|
15
|
+
values <=> other.values
|
16
|
+
end
|
17
|
+
|
18
|
+
def invert
|
19
|
+
Tuple(*values.reverse)
|
20
|
+
end
|
21
|
+
|
22
|
+
def_delegators :values,
|
23
|
+
:length,
|
24
|
+
:first,
|
25
|
+
:last,
|
26
|
+
:[]
|
27
|
+
|
28
|
+
alias_method :arity, :length
|
29
|
+
|
30
|
+
protected
|
31
|
+
attr_reader :values
|
32
|
+
end
|
33
|
+
|
34
|
+
def Tuple(*values)
|
35
|
+
Tuple.new(*values)
|
36
|
+
end
|
data/tuples.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'tuples/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |spec|
|
9
|
+
spec.name = 'tuples'
|
10
|
+
spec.version = Tuples::VERSION
|
11
|
+
spec.authors = ['Kamil Lelonek']
|
12
|
+
spec.email = ['squixy.sln@gmail.com']
|
13
|
+
spec.summary = %q{Ruby implementation for tuples known from functional programming}
|
14
|
+
spec.description = %q{Tuple combines a fixed number of items together so that they can be passed around as a whole. Unlike an array or list, a tuple can hold objects with different types but they are also immutable.}
|
15
|
+
spec.homepage = 'https://github.com/KamilLelonek/ruby-tuples'
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'pry-byebug', '~> 3.1.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.2.0'
|
25
|
+
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1.2'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tuples
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kamil Lelonek
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-27 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.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
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: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-collection_matchers
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.2
|
83
|
+
description: Tuple combines a fixed number of items together so that they can be passed
|
84
|
+
around as a whole. Unlike an array or list, a tuple can hold objects with different
|
85
|
+
types but they are also immutable.
|
86
|
+
email:
|
87
|
+
- squixy.sln@gmail.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- lib/tuples.rb
|
102
|
+
- lib/tuples/pair.rb
|
103
|
+
- lib/tuples/tuple.rb
|
104
|
+
- lib/tuples/version.rb
|
105
|
+
- tuples.gemspec
|
106
|
+
homepage: https://github.com/KamilLelonek/ruby-tuples
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.4.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Ruby implementation for tuples known from functional programming
|
129
|
+
test_files: []
|