kleisli 0.2.6 → 0.2.7

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: a943eddc108578f4e28c099359af9f4386b18b1f
4
- data.tar.gz: 0143498d991c38d67a60c9d36fdd160c3bd4a459
3
+ metadata.gz: 83625af4c953b13b6f862f7d6ad36ab3a39400d8
4
+ data.tar.gz: 84a969b0674429a2afe89828a302a2fef05d4961
5
5
  SHA512:
6
- metadata.gz: a1bda4f515cd9af93bff85b418b467afe61582c5fb04b518a1e8425f34bd827f8d0b494f268528b3cea9ca65a1acbd4ae97d7f840c984e485c27e2a419af051a
7
- data.tar.gz: fb37c38296fb37a98b3fdc7860f5bf8a44242d378cf6caca2665c86a0201415fea98528c47395db984c45c74446f919aaee311db5a9509c6d9d2100a69006247
6
+ metadata.gz: d29e1e270a601281f82096a7c7fad0b542476e14f8d10212be50dc10b876ba3306a72f9c76bc5ba50cf7a6644d0c3b09de6f9a358700c12f626a53bf6d9a1106
7
+ data.tar.gz: c713c14ef634c1658eea1fd8a5507fe1d49dde917687f53f8ff388567029e69ab07c3bb5b748ef9211d4452a05e49d90014da34cdf1b09cec62916cc65c21ae0
data/README.md CHANGED
@@ -192,6 +192,22 @@ Try { JSON.parse(json_string) }.fmap(&:symbolize_keys).to_maybe
192
192
  # => None()
193
193
  ```
194
194
 
195
+ ### `to_either`
196
+
197
+ Sometimes it's useful to interleave both `Try` and `Either`. To convert a `Try`
198
+ into a `Either` you can use `to_either`:
199
+
200
+ ```ruby
201
+ require "kleisli"
202
+
203
+ Try { JSON.parse(json_string) }.fmap(&:symbolize_keys).to_either
204
+
205
+ # If everything went well:
206
+ # => Right({ :my => "json", :with => "symbolized keys" })
207
+ # If an exception was thrown:
208
+ # => Left(#<JSON::ParserError: 757: unexpected token at 'json'>)
209
+ ```
210
+
195
211
  ## Either
196
212
 
197
213
  The Either monad is useful to express a pipeline of computations that might return an error object with some information.
@@ -29,6 +29,10 @@ module Kleisli
29
29
  def to_maybe
30
30
  Maybe::Some.new(@value)
31
31
  end
32
+
33
+ def to_either
34
+ Either::Right.new(@value)
35
+ end
32
36
  end
33
37
 
34
38
  class Failure < Try
@@ -47,6 +51,10 @@ module Kleisli
47
51
  def to_maybe
48
52
  Maybe::None.new
49
53
  end
54
+
55
+ def to_either
56
+ Either::Left.new(@exception)
57
+ end
50
58
  end
51
59
  end
52
60
  end
@@ -1,3 +1,3 @@
1
1
  module Kleisli
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -17,6 +17,14 @@ class TryTest < Minitest::Test
17
17
  assert_equal None(), Try { 10 / 0 }.to_maybe
18
18
  end
19
19
 
20
+ def test_to_either_success
21
+ assert_equal Right(2), Try { 10 / 5 }.to_either
22
+ end
23
+
24
+ def test_to_either_failure
25
+ assert_kind_of ZeroDivisionError, Try { 10 / 0 }.to_either.left
26
+ end
27
+
20
28
  def test_fmap_success
21
29
  assert_equal 4, Try { 10 / 5 }.fmap { |x| x * 2 }.value
22
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kleisli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep M. Bach
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-20 00:00:00.000000000 Z
12
+ date: 2015-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.2.2
107
+ rubygems_version: 2.4.5.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Usable, idiomatic common monads in Ruby
@@ -115,4 +115,3 @@ test_files:
115
115
  - test/kleisli/maybe_test.rb
116
116
  - test/kleisli/try_test.rb
117
117
  - test/test_helper.rb
118
- has_rdoc: