either-monad 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f42a1d3e60ecd54825b268c689ee48be2de686f5
4
+ data.tar.gz: 080abd900338fb3b82b37dcd9b03869f96be3cdb
5
+ SHA512:
6
+ metadata.gz: 19963b9a3f84aed941a21e54fc0ec7e428008da8fc6bb45ef948120f1e4180bee50732760478084f3a30fff8b84e176eda608ca6a4437eefb1c9e05e45335c63
7
+ data.tar.gz: e59f50faab6fb6cb91a2dc2866062452b0933e43b597bd49ee02667abad01a68724823074d57aaaa05a4994111ed1e9d9b454c41d2627921a02c2e6ef6c723ee
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Denis Redozubov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,21 @@
1
+ Either
2
+ ======
3
+
4
+ Dead simple error context framework aka Either monad. Goal of this gem is to
5
+ provide solid ground to control flow without exceptions and allow simple and
6
+ expressive chaining failure context.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ in terminal
12
+
13
+ ``` terminal
14
+ $ gem install either-monad
15
+ ```
16
+
17
+ or in **Gemfile**
18
+
19
+ ``` ruby
20
+ gem 'either-monad'
21
+ ```
@@ -0,0 +1,29 @@
1
+ $LOAD_PATH << File.expand_path('./lib')
2
+ require "rotary"
3
+
4
+ task :build do
5
+ system "gem build either-monad.gemspec"
6
+ end
7
+
8
+ task :release => :build do
9
+ system "gem push either-monad-#{Either::VERSION}"
10
+ end
11
+
12
+ task :console do
13
+ require 'pry'
14
+ require 'either-monad'
15
+ ARGV.clear
16
+ Pry.start
17
+ end
18
+ task :c => :console
19
+
20
+ require 'rake/testtask'
21
+
22
+ Rake::TestTask.new do |t|
23
+ t.libs << "lib"
24
+ t.libs << "spec"
25
+ t.test_files = FileList['spec/**/*_spec.rb']
26
+ t.verbose = true
27
+ end
28
+ task :spec => :test
29
+ task :default => :test
@@ -0,0 +1,50 @@
1
+ # Do not instantiate this class EVER
2
+ class Either
3
+ attr_accessor :value
4
+
5
+ def initialize(value)
6
+ @value = value
7
+ end
8
+
9
+ def self.[](value)
10
+ new(value)
11
+ end
12
+
13
+ def success?
14
+ !failure?
15
+ end
16
+
17
+ def failure?
18
+ !success?
19
+ end
20
+
21
+ # This is haskell's >>= operator (pronounced "bind")
22
+ # Basically, it's:
23
+ # (>>=) :: forall a b. m a -> (a -> m b) -> m b
24
+ # see https://hackage.haskell.org/package/base-4.2.0.1/docs/Prelude.html#9
25
+ # for more details
26
+ def bind(f)
27
+ success? ? f.call(value) : self
28
+ end
29
+
30
+ # Applies function f to unwrapped value of self.
31
+ # It's type is:
32
+ # either :: (a -> c) -> (b -> c) -> Either a b -> c
33
+ # for further details see
34
+ # https://hackage.haskell.org/package/base-4.2.0.1/docs/src/Data-Either.html#either
35
+ #
36
+ # Hopefully keyword arguments will improve readability
37
+ def either(failure:, success:)
38
+ failure? ? failure.call(value) : success.call(value)
39
+ end
40
+ end
41
+
42
+ class Failure < Either
43
+ define_method :failure?, -> { true }
44
+ end
45
+
46
+ class Success < Either
47
+ define_method :success?, -> { true }
48
+ end
49
+
50
+ require 'either/version'
@@ -0,0 +1,4 @@
1
+ module Either
2
+ VERSION = '0.0.1'
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: either-monad
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Denis Redozubov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 10.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '10.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 10.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: pry
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.12.6
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.9'
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 0.9.12.6
53
+ description: |2
54
+ Simple Either monad implementation. Great way to chain actions that may result in error and keep their context, both successful and erroneous.
55
+ email: denis.redozubov@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - LICENSE
61
+ - README.md
62
+ - Rakefile
63
+ - lib/either.rb
64
+ - lib/either/version.rb
65
+ homepage: http://github.com/dredozubov/either-monad
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.2.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Dead simple error context framework aka Either monad.
89
+ test_files: []
90
+ has_rdoc: false