optional 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
6
+ - rbx-19mode
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optional (0.0.5)
4
+ optional (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.2.1)
10
10
  multi_json (1.7.2)
11
+ rake (10.0.4)
11
12
  rspec (2.13.0)
12
13
  rspec-core (~> 2.13.0)
13
14
  rspec-expectations (~> 2.13.0)
@@ -26,5 +27,6 @@ PLATFORMS
26
27
 
27
28
  DEPENDENCIES
28
29
  optional!
30
+ rake
29
31
  rspec
30
32
  simplecov
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # optional
2
2
  ## option types to make nils a thing of the past
3
3
 
4
+ [![Build Status](https://travis-ci.org/rsslldnphy/optional.png?branch=master)](https://travis-ci.org/rsslldnphy/optional)
5
+ [![Code Climate](https://codeclimate.com/github/rsslldnphy/optional.png)](https://codeclimate.com/github/rsslldnphy/optional)
6
+
4
7
  Tony Hoare, inventor of the null reference, calls it his "billion-dollar mistake".
5
8
  You will be no stranger to the ubiquitous `NoMethodError: undefined method 'foo' for nil:NilClass`.
6
9
  But it doesn't have to be this way.
@@ -114,6 +117,11 @@ You can simply use the `collection` key when rendering the partial - you don't e
114
117
 
115
118
  <%= render partial: 'hat', collection: @person.hat %>
116
119
 
120
+ You can also use `select` and `reject` to assert things about the value:
121
+
122
+ Some[5].select(&:odd?) # => Some[5]
123
+ Some[5].reject(&:odd?) # => None
124
+
117
125
  And one last useful example, `flatten`:
118
126
 
119
127
  Some[Some[5], None, Some[7]].flatten # => Some[5,7]
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => :spec
5
+
6
+ require 'rspec/core/rake_task'
7
+
8
+ RSpec::Core::RakeTask.new
@@ -1 +1,7 @@
1
- require_relative 'optional/all'
1
+ require 'optional/option/enumerable'
2
+ require 'optional/option/errors'
3
+ require 'optional/option/match'
4
+
5
+ require 'optional/option'
6
+ require 'optional/some'
7
+ require 'optional/none'
@@ -15,7 +15,7 @@ module Option
15
15
  end
16
16
 
17
17
  def map_through(*methods)
18
- map &methods.reduce(->(x){x}){ |acc, m| ->(x) { acc.call(x).send(m) } }
18
+ map &methods.reduce(lambda { |x| x}) { |acc, m| lambda { |x| acc.call(x).send(m) } }
19
19
  end
20
20
 
21
21
  def map
@@ -42,7 +42,7 @@ module Option
42
42
 
43
43
  class SomeClause
44
44
 
45
- def initialize(guard=always, block)
45
+ def initialize(guard=always, block=lambda{})
46
46
  @guard = guard
47
47
  @block = block
48
48
  end
@@ -60,7 +60,7 @@ module Option
60
60
  attr_reader :block
61
61
 
62
62
  def guard
63
- @guard.is_a?(Proc) ? @guard : ->(x) { x == @guard }
63
+ @guard.is_a?(Proc) ? @guard : (lambda { |x| x == @guard })
64
64
  end
65
65
 
66
66
  end
@@ -37,7 +37,7 @@ class Some
37
37
 
38
38
  def merge(other, &block)
39
39
  other.match do |m|
40
- m.some { |v| block.nil? ? Some[*value, v] : Some[block.call(value, v)] }
40
+ m.some { |v| block.nil? ? Some[([value] + [v]).flatten] : Some[block.call(value, v)] }
41
41
  m.none { self }
42
42
  end
43
43
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'optional'
3
- s.version = '0.0.6'
3
+ s.version = '0.0.7'
4
4
  s.date = '2013-04-19'
5
5
  s.summary = "Optional values with pattern matching"
6
6
  s.description = "Make nils a thing of the past with Options!"
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.require_paths = ["lib"]
12
12
  s.homepage = 'http://github.com/rsslldnphy/optional'
13
13
 
14
+ s.add_development_dependency "rake"
14
15
  s.add_development_dependency "rspec"
15
16
  s.add_development_dependency "simplecov"
16
17
 
@@ -43,14 +43,9 @@ describe Option::Enumerable do
43
43
  end
44
44
 
45
45
  describe "#flat_map" do
46
- it 'works as expected over an array of options' do
47
- [None, Some[3], None, Some[2]].flat_map do |x|
48
- x.map(&:succ)
49
- end.should eq [4,3]
50
- end
51
46
 
52
- it 'also works for a some that returns a nested some' do
53
- x = Some[stub(y: Some[4])]
47
+ it 'works for a some that returns a nested some' do
48
+ x = Some[stub(:y => Some[4])]
54
49
  x.flat_map(&:y).should eq Some[4]
55
50
  end
56
51
  end
File without changes
@@ -33,8 +33,8 @@ describe Option do
33
33
 
34
34
  it "can take a lambda as a guard to match against" do
35
35
  Some[cat].match do |m|
36
- m.some ->(pet) { pet.name == "DOGGIE!" } { :fishsticks }
37
- m.some ->(pet) { pet.name == "MOGGIE!" } { :canteloupe }
36
+ m.some lambda { |pet| pet.name == "DOGGIE!" } do :fishsticks end
37
+ m.some lambda { |pet| pet.name == "MOGGIE!" } do :canteloupe end
38
38
  end.should eq :canteloupe
39
39
  end
40
40
  end
@@ -4,8 +4,8 @@ SimpleCov.start do
4
4
  end
5
5
 
6
6
  require 'rspec'
7
- require_relative 'support/cat'
8
- require_relative '../lib/optional'
7
+ require 'support/cat'
8
+ require 'optional'
9
9
 
10
10
 
11
11
  RSpec.configure do |config|
metadata CHANGED
@@ -1,62 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: optional
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.6
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 7
10
+ version: 0.0.7
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Russell Dunphy
9
14
  - Radek Molenda
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2013-04-19 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rspec
17
- requirement: !ruby/object:Gem::Requirement
18
+
19
+ date: 2013-04-19 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rake
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
23
33
  type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
24
37
  prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
26
39
  none: false
27
- requirements:
28
- - - ! '>='
29
- - !ruby/object:Gem::Version
30
- version: '0'
31
- - !ruby/object:Gem::Dependency
32
- name: simplecov
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '0'
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
39
47
  type: :development
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: simplecov
40
51
  prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
42
53
  none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
47
63
  description: Make nils a thing of the past with Options!
48
- email:
64
+ email:
49
65
  - russell@russelldunphy.com
50
66
  - radek.molenda@gmail.com
51
67
  executables: []
68
+
52
69
  extensions: []
70
+
53
71
  extra_rdoc_files: []
54
- files:
72
+
73
+ files:
55
74
  - .gitignore
75
+ - .travis.yml
56
76
  - Gemfile
57
77
  - Gemfile.lock
58
78
  - LICENSE.md
59
79
  - README.md
80
+ - Rakefile
60
81
  - lib/optional.rb
61
82
  - lib/optional/all.rb
62
83
  - lib/optional/none.rb
@@ -69,39 +90,49 @@ files:
69
90
  - optional.gemspec
70
91
  - spec/lib/optional/none_spec.rb
71
92
  - spec/lib/optional/option/enumerable_spec.rb
93
+ - spec/lib/optional/option/match_spec.rb
72
94
  - spec/lib/optional/option_spec.rb
73
95
  - spec/lib/optional/some_spec.rb
74
96
  - spec/spec_helper.rb
75
97
  - spec/support/cat.rb
76
98
  homepage: http://github.com/rsslldnphy/optional
77
99
  licenses: []
100
+
78
101
  post_install_message:
79
102
  rdoc_options: []
80
- require_paths:
103
+
104
+ require_paths:
81
105
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
83
107
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
114
+ version: "0"
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
116
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
123
+ version: "0"
94
124
  requirements: []
125
+
95
126
  rubyforge_project:
96
127
  rubygems_version: 1.8.25
97
128
  signing_key:
98
129
  specification_version: 3
99
130
  summary: Optional values with pattern matching
100
- test_files:
131
+ test_files:
101
132
  - spec/lib/optional/none_spec.rb
102
133
  - spec/lib/optional/option/enumerable_spec.rb
134
+ - spec/lib/optional/option/match_spec.rb
103
135
  - spec/lib/optional/option_spec.rb
104
136
  - spec/lib/optional/some_spec.rb
105
137
  - spec/spec_helper.rb
106
138
  - spec/support/cat.rb
107
- has_rdoc: