ribimaybe 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +11 -7
- data/lib/ribimaybe.rb +9 -1
- data/lib/version.rb +1 -1
- data/spec/bug_spec.rb +0 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZWM1YzAwN2MyNjg4ZTM1NGUyMmY4Y2Q0ODhhOTgxYzMzOGMxZDMxYg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5eaabf0383c05d88afb353a4ed3dbd0d9a6c0894
|
4
|
+
data.tar.gz: 9271691363379c9749a5f5f7d9376e2e54b9f358
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YmQ0ODQ3NDllNmE4NTU5MWExYjBlZGY5Mzk1ZTc2MzM1MTE0ZjUwNWM4ZWNm
|
11
|
-
MmJjYmZhNzI4NzBlMTQ1ODFjZjU0YjllYzcxYjkyNzVmYzVhNzQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODc5NDZmZTJkZTEzYTJjYWI5NjU2ZTY4YzJiOGQ0ZjMxZjg5MTBkZDVmNTRk
|
14
|
-
M2QwZmE1NDY4YmEwZDljOGM2YmVkOGZmZWQ4NTJhZDM4NzRhZTI1OTkxMWZm
|
15
|
-
NDQzZTE1YzcyMGExMDczMTY1NDg5MjRkOTBhMWM1YzY1Y2E3NTU=
|
6
|
+
metadata.gz: 8157d075f048b7b0f1af57cbc0b936b596ed8eb6c7d25c3a19455cac0b9ddfea9e8d60f49a5b7ae5331d8e4ec899e0b1ee88a3afe962b52e35542bba404ca552
|
7
|
+
data.tar.gz: 99921ff3c5289207a063985b424bc038b5a2493f7c6112ec730a28f4b561f1b2228582bd99208ef8a099ceab9ed132791707735da2a90a54ba4af3bf605947df
|
data/README.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
> "Flavouring the ocean with a teaspoon of sugar."
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/ribimaybe.svg)](http://badge.fury.io/rb/ribimaybe)
|
6
|
-
[![Travis](https://travis-ci.org/
|
6
|
+
[![Travis](https://travis-ci.org/filib/ribimaybe.svg?branch=master)](http://travis-ci.org/filib/ribimaybe)
|
7
7
|
[![Code Climate](https://codeclimate.com/github/unsymbol/ribimaybe.png)](https://codeclimate.com/github/unsymbol/ribimaybe)
|
8
8
|
|
9
9
|
![](maybe.gif)
|
10
10
|
|
11
|
-
A tiny Ruby library that provides a Maybe datatype which is a Functor,
|
11
|
+
A tiny Ruby library that provides a Maybe datatype which is a Functor,
|
12
12
|
Applicative Functor and Monad.
|
13
13
|
|
14
14
|
## Installation
|
@@ -27,8 +27,8 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
This is a small library and so it doesn't offer lots of creature comforts. The
|
31
|
-
one escape hatch it does offer is the ability to convert `nil` into `Nothing`.
|
30
|
+
This is a small library and so it doesn't offer lots of creature comforts. The
|
31
|
+
one escape hatch it does offer is the ability to convert `nil` into `Nothing`.
|
32
32
|
|
33
33
|
``` ruby
|
34
34
|
include Ribimaybe::Maybe
|
@@ -37,13 +37,13 @@ Maybe(42) # => Just(42)
|
|
37
37
|
Maybe(nil) # => Nothing
|
38
38
|
```
|
39
39
|
|
40
|
-
And that's it, once you have lifted your value into a `Maybe` you can treat it
|
40
|
+
And that's it, once you have lifted your value into a `Maybe` you can treat it
|
41
41
|
as a `Functor`, `Applicative Functor` or `Monad`. If you want to pull your value
|
42
42
|
out of a `Maybe`, we got you covered too.
|
43
43
|
|
44
44
|
``` ruby
|
45
45
|
Just(42).maybe(false) { |x| x == 42 } # => true
|
46
|
-
Nothing.maybe(false) { |x| x == 42 } # => false
|
46
|
+
Nothing.maybe(false) { |x| x == 42 } # => false
|
47
47
|
```
|
48
48
|
|
49
49
|
### Functor [\[info\]](http://learnyouahaskell.com/functors-applicative-functors-and-monoids)
|
@@ -61,7 +61,7 @@ Nothing.map { |x| x * x } # => Nothing
|
|
61
61
|
``` ruby
|
62
62
|
include Ribimaybe::Maybe
|
63
63
|
|
64
|
-
# Wrap functions inside functors and apply them to other functors!
|
64
|
+
# Wrap functions inside functors and apply them to other functors!
|
65
65
|
Just do |x, y|
|
66
66
|
x * y
|
67
67
|
end.apply(pure(42)).apply(pure(42)) # => Just(1764)
|
@@ -69,6 +69,10 @@ end.apply(pure(42)).apply(pure(42)) # => Just(1764)
|
|
69
69
|
Just do |x|
|
70
70
|
x * x
|
71
71
|
end.apply(Nothing) # => Nothing
|
72
|
+
|
73
|
+
# We can't define <*> but we can define a different operator with the same
|
74
|
+
# semantics!
|
75
|
+
Just { |x, y| x * y } >> pure(42) >> pure(42) # => Just(1764)
|
72
76
|
```
|
73
77
|
|
74
78
|
### Monad [\[info\]](http://www.learnyouahaskell.com/a-fistful-of-monads)
|
data/lib/ribimaybe.rb
CHANGED
@@ -20,10 +20,12 @@ module Ribimaybe
|
|
20
20
|
|
21
21
|
alias_method :inspect, :to_s
|
22
22
|
|
23
|
-
# Compares a
|
23
|
+
# Compares a Nothing to another Maybe.
|
24
24
|
#
|
25
25
|
# ==== Attributes
|
26
26
|
#
|
27
|
+
# * +other+ - The other Maybe value.
|
28
|
+
#
|
27
29
|
Contract Or[Nothing, Just] => Bool
|
28
30
|
def self.===(other)
|
29
31
|
self == other
|
@@ -50,6 +52,10 @@ module Ribimaybe
|
|
50
52
|
self
|
51
53
|
end
|
52
54
|
|
55
|
+
class << self
|
56
|
+
alias_method :>>, :apply
|
57
|
+
end
|
58
|
+
|
53
59
|
# No operation. Always returns Nothing.
|
54
60
|
#
|
55
61
|
Contract Proc => Nothing
|
@@ -144,6 +150,8 @@ module Ribimaybe
|
|
144
150
|
value.map { |v| @value.curry.(v) }
|
145
151
|
end
|
146
152
|
|
153
|
+
alias_method :>>, :apply
|
154
|
+
|
147
155
|
# Applies fn to value inside Just (note contract constraint).
|
148
156
|
#
|
149
157
|
# ==== Attributes
|
data/lib/version.rb
CHANGED
data/spec/bug_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ribimaybe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unsymbol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,42 +28,42 @@ dependencies:
|
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -113,17 +113,17 @@ require_paths:
|
|
113
113
|
- lib
|
114
114
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- -
|
116
|
+
- - '>='
|
117
117
|
- !ruby/object:Gem::Version
|
118
118
|
version: 1.9.3
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
126
|
+
rubygems_version: 2.0.2
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: A tiny Ruby library that provides a Maybe datatype which is a Functor, Applicative
|
@@ -135,3 +135,4 @@ test_files:
|
|
135
135
|
- spec/maybe_spec.rb
|
136
136
|
- spec/monad_spec.rb
|
137
137
|
- spec/spec_helper.rb
|
138
|
+
has_rdoc:
|