data.maybe 0.0.12 → 0.0.13

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: 761536bda9c622eb3cdf0ee0e1ab5fb64ea15887
4
- data.tar.gz: 70c2b0812c9ba3a7e1e7bb19e55a7104399a19d6
3
+ metadata.gz: cf5826f8ce957c248e621d76ca965962825c43a6
4
+ data.tar.gz: 861712e3517ade55bc00de8a541b3a16c2b28ed9
5
5
  SHA512:
6
- metadata.gz: c3292d8719abb3e713503267fd042dd916625f0e5d47356fea718f114691d1a89091a7535d0f888372df388e4a7b9725a42cba4aa6b9bc12d46111965bb4bff7
7
- data.tar.gz: f8582f676b767721161f35bb259e58108d44cbe38a22d5ed88e94ae4268070a657dc1ab1d02146d1d494c291ad6b6e458ac9c8828cb846ba1eabec234ed64b28
6
+ metadata.gz: fbddafc1ca82703d5c6590c9f1aaa8085bbaec368614028c9676e0de8089a7c4c8f8244cbb2cdccb147f78f096991dfe738b26a9b94876a18e80b3c2f69d7a4d
7
+ data.tar.gz: af3d0b57a63c5ee41f20131f97935754a25e9f08d7d177bd130991cd7d36a6a569e828c38cf0ff185cc51aa95a53bb5fbb9d95d5f7a9ae40af0674155f77c839
@@ -13,7 +13,7 @@ module Control
13
13
  raise 'apply No defined'
14
14
  end
15
15
  end
16
-
16
+
17
17
  module Monad
18
18
  extend Helper
19
19
  include Functor
@@ -23,9 +23,9 @@ module Control
23
23
  end
24
24
 
25
25
  alias_names [:bind, :chain], :flat_map
26
-
27
- def >> k
28
- self.flat_map { |_| k }
26
+
27
+ def >>(k)
28
+ flat_map { |_| k }
29
29
  end
30
30
  end
31
31
  end
@@ -9,17 +9,17 @@ module Maybe
9
9
  include UnionType
10
10
  # Either only contain one value @v
11
11
  # @return [Either]
12
- def initialize v=nil
12
+ def initialize(v = nil)
13
13
  @v = v
14
14
  end
15
15
 
16
16
  # get value `a` out from `Right a`, otherwise return `e`
17
- def get_or_else e
17
+ def get_or_else(e)
18
18
  case self
19
- when Just
20
- @v
21
- else
22
- e
19
+ when Just
20
+ @v
21
+ else
22
+ e
23
23
  end
24
24
  end
25
25
 
@@ -38,7 +38,7 @@ module Maybe
38
38
  self
39
39
  end
40
40
  end
41
-
41
+
42
42
  # it override {Monad#flat_map}, as Haskell's `>flat_map` method
43
43
  # if it's {Right}, pass the value to #flat_map's block, and flat the result
44
44
  # of the block.
@@ -68,12 +68,12 @@ module Maybe
68
68
  # Right.new(1).when({Left: ->x{x+1}, _: ->x{x-1} }) # => 0
69
69
  # ```
70
70
  # @return [Either]
71
- def when what
71
+ def when(what)
72
72
  current_class = self.class.to_s.to_sym
73
73
  if what.include? current_class
74
- what[current_class].(@v)
74
+ what[current_class].call(@v)
75
75
  elsif what.include? :_
76
- what[:_].(@v)
76
+ what[:_].call(@v)
77
77
  end
78
78
  end
79
79
 
@@ -83,18 +83,17 @@ module Maybe
83
83
  when Just
84
84
  "#<Just #{@v}>"
85
85
  else
86
- "#<Nothing>"
86
+ '#<Nothing>'
87
87
  end
88
88
  end
89
- alias_method :inspect, :to_s
89
+ alias inspect to_s
90
90
  end
91
91
 
92
-
93
92
  class Nothing
94
93
  include Singleton
95
94
  include Maybe
96
-
97
- def == other
95
+
96
+ def ==(other)
98
97
  case other
99
98
  when Nothing
100
99
  true
@@ -108,8 +107,8 @@ Nothing = Nothing.instance
108
107
 
109
108
  class Just
110
109
  include Maybe
111
-
112
- def == other
110
+
111
+ def ==(other)
113
112
  case other
114
113
  when Just
115
114
  other.map { |v| return v == @v }
@@ -1,9 +1,9 @@
1
1
  module Helper
2
- def alias_names names, m
3
- names.each do |name|
4
- define_method(name) do |*args, &block|
5
- self.send(m, *args, &block)
2
+ def alias_names(names, m)
3
+ names.each do |name|
4
+ define_method(name) do |*args, &block|
5
+ send(m, *args, &block)
6
6
  end
7
7
  end
8
- end
8
+ end
9
9
  end
@@ -1,21 +1,21 @@
1
1
  require 'helper'
2
2
  module UnionType
3
3
  extend Helper
4
- # similar to Scala's `match` for case class
5
- #
6
- # will pattern match the value out and pass to matched lambda
7
- # ```ruby
8
- # Right.new(1).when({Right: ->x{x+1} }) # => 2
9
- # Right.new(1).when({Left: ->x{x+1}) # => nil
10
- # Right.new(1) =~ ({Left: ->x{x+1}, _: ->x{x-1} }) # => 0
11
- # ```
12
- # @return [Either]
13
- def when what
4
+ # similar to Scala's `match` for case class
5
+ #
6
+ # will pattern match the value out and pass to matched lambda
7
+ # ```ruby
8
+ # Right.new(1).when({Right: ->x{x+1} }) # => 2
9
+ # Right.new(1).when({Left: ->x{x+1}) # => nil
10
+ # Right.new(1) =~ ({Left: ->x{x+1}, _: ->x{x-1} }) # => 0
11
+ # ```
12
+ # @return [Either]
13
+ def when(what)
14
14
  current_class = self.class.to_s.to_sym
15
15
  if what.include? current_class
16
- what[current_class].(@v)
16
+ what[current_class].call(@v)
17
17
  elsif what.include? :_
18
- what[:_].(@v)
18
+ what[:_].call(@v)
19
19
  end
20
20
  end
21
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data.maybe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jichao Ouyang