monadic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## v0.2.0 (not released)
3
+ ## v0.2.1
4
+ Nothing has no method #name ... will need to use `BasicObject`
5
+
6
+ ## v0.2.0
4
7
  **BREAKING CHANGES**
5
8
 
6
9
  `Monad#map` does not recognize `Enumerables` automatically anymore. It just maps, as a `Functor`.
data/lib/monadic/maybe.rb CHANGED
@@ -46,6 +46,8 @@ module Monadic
46
46
  # Represents a NullObject
47
47
  class Nothing < Maybe
48
48
  class << self
49
+ undef name
50
+
49
51
  def fetch(default=nil)
50
52
  return self if default.nil?
51
53
  return default
@@ -1,3 +1,3 @@
1
1
  module Monadic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ # Is a transformation C[A -> B] -> C[A] -> C[B]
4
+ module Applicative
5
+ # @param [Proc, lambda] proc
6
+ # @return [Functor] functor
7
+ def apply(value)
8
+ return value.class.unit(@value.call(value.fetch))
9
+ end
10
+ alias :<< :apply
11
+ end
12
+
13
+ class Maybe
14
+ include Applicative
15
+ end
16
+
17
+ class Either
18
+ include Applicative
19
+ end
20
+
21
+
22
+ describe Applicative do
23
+ it 'allows applying monads' do
24
+ l = lambda {|x,y| x + y }.curry
25
+ res = Just(l) << Just(1) << Just(3)
26
+ res.should == Just(4)
27
+ end
28
+
29
+ it 'applicative composition success' do
30
+ settings = -> { Success({setting: 1}) }
31
+ db = ->(pr) { [pr, :x, :y, ] }
32
+ ws = ->(pr) { "Rock'n'Roll #{pr}" }
33
+ construct = ->(preferences, database, webservice) { "#{preferences} #{database} #{webservice}" }.curry
34
+
35
+ res = Either(construct) >= settings >= db >= ws
36
+ res.should == Success("Rock'n'Roll [{:setting=>1}, :x, :y]")
37
+ end
38
+
39
+ it 'applicative composition failure' do
40
+ settings = -> { Success({a: 1}) }
41
+ db = ->(pr) { Failure('too many connections') }
42
+ ws = ->(pr) { raise 'should have never called me' }
43
+ construct = ->(preferences, database, webservice) { "never executed" }.curry
44
+
45
+ res = Either(construct) + settings + db + ws
46
+ res.should == Failure('too many connections')
47
+ end
48
+ end
data/spec/maybe_spec.rb CHANGED
@@ -47,6 +47,11 @@ describe Monadic::Maybe do
47
47
  Nothing.empty?.should be_true
48
48
  Nothing.truly?.should be_false
49
49
  end
50
+
51
+ it 'returns Nothing when calling #name' do
52
+ hd = Nothing
53
+ hd.name.should == Monadic::Nothing
54
+ end
50
55
  end
51
56
 
52
57
  describe Monadic::Just do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monadic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-17 00:00:00.000000000 Z
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -152,6 +152,7 @@ files:
152
152
  - monadic.gemspec
153
153
  - spec/core_ext/object_spec.rb
154
154
  - spec/either_spec.rb
155
+ - spec/examples/applicative_spec.rb
155
156
  - spec/jruby_fixes.rb
156
157
  - spec/maybe_spec.rb
157
158
  - spec/monad_axioms.rb
@@ -170,25 +171,31 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  - - ! '>='
171
172
  - !ruby/object:Gem::Version
172
173
  version: '0'
174
+ segments:
175
+ - 0
176
+ hash: 634459162394168513
173
177
  required_rubygems_version: !ruby/object:Gem::Requirement
174
178
  none: false
175
179
  requirements:
176
180
  - - ! '>='
177
181
  - !ruby/object:Gem::Version
178
182
  version: '0'
183
+ segments:
184
+ - 0
185
+ hash: 634459162394168513
179
186
  requirements: []
180
187
  rubyforge_project:
181
- rubygems_version: 1.8.23
188
+ rubygems_version: 1.8.24
182
189
  signing_key:
183
190
  specification_version: 3
184
191
  summary: see README
185
192
  test_files:
186
193
  - spec/core_ext/object_spec.rb
187
194
  - spec/either_spec.rb
195
+ - spec/examples/applicative_spec.rb
188
196
  - spec/jruby_fixes.rb
189
197
  - spec/maybe_spec.rb
190
198
  - spec/monad_axioms.rb
191
199
  - spec/monad_spec.rb
192
200
  - spec/spec_helper.rb
193
201
  - spec/validation_spec.rb
194
- has_rdoc: