unsound 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/unsound/data/maybe.rb +17 -0
- data/lib/unsound/version.rb +1 -1
- data/spec/unit/unsound/data/maybe_spec.rb +27 -0
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 969cc5da6572e62fb76773536cd7bc3da5a0df11
|
4
|
+
data.tar.gz: 32ed2346c15304d27addb2b0d623ca68738f9f84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee5567a88fe014b0c6afa9652d71a52e00575017206fd4319d0c8bf018f87b646cddc8aa3ade4e29cad9e612743aa8322caf13a62376c8e3524735090fbb03ef
|
7
|
+
data.tar.gz: 3f0ac46526183250bbe08f3bcaf8946f9dc6eff7760265c9cdb1cc10e0c0f9f67f149b006bfa7a539e497b197bf7ed0315bcfacf0f0706aec395d6822e9ea440
|
data/.travis.yml
CHANGED
data/lib/unsound/data/maybe.rb
CHANGED
@@ -18,6 +18,7 @@ module Unsound
|
|
18
18
|
abstract_method :fmap
|
19
19
|
abstract_method :>>
|
20
20
|
|
21
|
+
abstract_method :maybe
|
21
22
|
abstract_method :and_then
|
22
23
|
abstract_method :or_else
|
23
24
|
|
@@ -53,6 +54,14 @@ module Unsound
|
|
53
54
|
def or_else(f = nil, &blk)
|
54
55
|
(f || blk).call
|
55
56
|
end
|
57
|
+
|
58
|
+
# Call the specified function with no arguments
|
59
|
+
#
|
60
|
+
# @param _ [#call] a function that will never be called
|
61
|
+
# @param f [#call] a function that takes no arguments
|
62
|
+
def maybe(_, f)
|
63
|
+
f[]
|
64
|
+
end
|
56
65
|
end
|
57
66
|
|
58
67
|
class Just < Maybe
|
@@ -82,6 +91,14 @@ module Unsound
|
|
82
91
|
def or_else(*)
|
83
92
|
self
|
84
93
|
end
|
94
|
+
|
95
|
+
# Call a function on the value in the {Data::Just}
|
96
|
+
#
|
97
|
+
# @param f [#call] a function capable of processing the value
|
98
|
+
# @param _ [#call] a function that will never be called
|
99
|
+
def maybe(f, _)
|
100
|
+
f[value]
|
101
|
+
end
|
85
102
|
end
|
86
103
|
end
|
87
104
|
end
|
data/lib/unsound/version.rb
CHANGED
@@ -89,4 +89,31 @@ RSpec.describe Unsound::Data::Maybe do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
93
|
+
describe "#maybe" do
|
94
|
+
let(:just_fn) { double(:just_fn) }
|
95
|
+
let(:nothing_fn) { double(:nothing_fn) }
|
96
|
+
|
97
|
+
let(:just_result) { double(:just_result) }
|
98
|
+
let(:nothing_result) { double(:nothing_result) }
|
99
|
+
|
100
|
+
context "a just" do
|
101
|
+
let(:just) { Unsound::Data::Just.new(value) }
|
102
|
+
|
103
|
+
it "calls the just function with the value" do
|
104
|
+
allow(just_fn).to receive(:[]).
|
105
|
+
with(value).and_return(just_result)
|
106
|
+
expect(just.maybe(just_fn, nothing_fn)).to eq(just_result)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "a nothing" do
|
111
|
+
let(:nothing) { Unsound::Data::Nothing.new }
|
112
|
+
|
113
|
+
it "calls the nothing function" do
|
114
|
+
allow(nothing_fn).to receive(:[]).and_return(nothing_result)
|
115
|
+
expect(nothing.maybe(just_fn, nothing_fn)).to eq(nothing_result)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
92
119
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unsound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Swan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: abstract_type
|
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: :runtime
|
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: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
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: '1.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
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
|
description:
|
@@ -73,11 +73,11 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .rubocop.yml
|
79
|
-
- .rubocop_todo.yml
|
80
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".rubocop_todo.yml"
|
80
|
+
- ".travis.yml"
|
81
81
|
- Gemfile
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
@@ -107,17 +107,17 @@ require_paths:
|
|
107
107
|
- lib
|
108
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.2.2
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: General functional concepts inspired by Haskell, implemented in Ruby.
|