unsound 0.0.3 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c645e777dc983c390c247a59c5f2de02727346b
4
- data.tar.gz: a316ea5ccba27d63f3a823344e7c256f36056f1c
3
+ metadata.gz: 4fef2d390995831f611de3a87edb4a2c90399c72
4
+ data.tar.gz: 666f8821e7286223fb5d5e7ba03b858dabf5b531
5
5
  SHA512:
6
- metadata.gz: 0c2101d6baca2654803b9edcca62d5f2e7967a29114f252a7e1c7dbef763ffaa98c0bcaa00e042cf524014a04f13c46de7a7962f43e1857792a24f5921f221c0
7
- data.tar.gz: 59979f8819eff54c06cab5d71eb3a8e27e2e555b1185a6721df4235d1512bd443affd17ed3a0a1adea2b6ae7609442ae0bf9e6feddd12c88e69cdc29e40477de
6
+ metadata.gz: 9cebd7a4a5c0939bee370a90ae0a22283692f148fc4aa6fb4d701483449fec260e3adf04fdd25599fe1626616fadaf519f648946a679779d646de4bcfbf84a31
7
+ data.tar.gz: 63b4956bcd70e4cd6b3886f9aec0dc1366e963dcd2361cdd4aec67f982b32aee6b04d0a6c46a6629bfdb2216d0ef81d6140e8dd03316124fc84a52449550fe10
@@ -16,5 +16,19 @@ module Unsound
16
16
  rescue
17
17
  Data::Left.new($ERROR_INFO)
18
18
  end
19
+
20
+ # Execute the block. If the block
21
+ # results in Nil, return {Data::Nothing},
22
+ # otherwise wrap the result in a {Data::Just}
23
+ #
24
+ # @param block [Block] the block to execute
25
+ # @return [Data::Nothing, Data::Just] an instance of {Data::Maybe}
26
+ def maybe(&block)
27
+ if (result = block.call).nil?
28
+ Data::Nothing.new
29
+ else
30
+ Data::Just.new(result)
31
+ end
32
+ end
19
33
  end
20
34
  end
@@ -1,3 +1,3 @@
1
1
  module Unsound
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -24,4 +24,26 @@ RSpec.describe Unsound::Control do
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ describe Unsound::Control, ".maybe" do
29
+ subject(:run_maybe) { Unsound::Control.maybe(&blk) }
30
+
31
+ context "the block returns nil" do
32
+ let(:blk) { -> { nil } }
33
+
34
+ it "returns Nothing" do
35
+ expect(run_maybe).to be_a(Unsound::Data::Nothing)
36
+ end
37
+ end
38
+
39
+ context "the block does not return nil" do
40
+ let(:blk) { -> { result } }
41
+ let(:result) { double(:result) }
42
+
43
+ it "returns a Just" do
44
+ expect(run_maybe).to be_a(Unsound::Data::Just)
45
+ expect(run_maybe.value).to eq(result)
46
+ end
47
+ end
48
+ end
27
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unsound
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Swan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-14 00:00:00.000000000 Z
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concord
@@ -129,3 +129,4 @@ test_files:
129
129
  - spec/unit/unsound/control_spec.rb
130
130
  - spec/unit/unsound/data/either_spec.rb
131
131
  - spec/unit/unsound/data/maybe_spec.rb
132
+ has_rdoc: