funkr 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,6 +71,13 @@ module Funkr
71
71
  end
72
72
  end
73
73
 
74
+ def unbox(default=nil)
75
+ self.match do |on|
76
+ on.just {|v| v }
77
+ on.nothing { default }
78
+ end
79
+ end
80
+
74
81
  class << self
75
82
  alias unit just
76
83
  alias pure just
@@ -81,14 +88,19 @@ module Funkr
81
88
  if value.nil? then self.nothing
82
89
  else self.just(value) end
83
90
  end
84
-
85
- def unbox(default=nil)
86
- self.match do |on|
87
- on.just {|v| v }
88
- on.nothing { default }
91
+
92
+ # concat :: [Maybe a] -> [a]
93
+ # The Maybe.concat function takes a list of Maybes and returns
94
+ # a list of all the Just values.
95
+ def self.concat(maybes)
96
+ maybes.inject([]) do |a, e|
97
+ e.match do |on|
98
+ on.just{|v| a + [v]}
99
+ on.nothing{ a }
100
+ end
89
101
  end
90
102
  end
91
-
103
+
92
104
  end
93
105
  end
94
106
  end
@@ -1,3 +1,3 @@
1
1
  module Funkr
2
- VERSION = "0.0.20"
2
+ VERSION = "0.0.21"
3
3
  end
@@ -50,6 +50,12 @@ puts Maybe.mconcat([Maybe.just(10),
50
50
  Maybe.nothing,
51
51
  Maybe.just(30)])
52
52
 
53
+ puts "\n> concat"
54
+ puts Maybe.concat([ Maybe.just(10),
55
+ Maybe.just(20),
56
+ Maybe.nothing,
57
+ Maybe.just(30) ]).inspect
58
+
53
59
  puts "\n> Comparisons"
54
60
  puts(m <=> m)
55
61
  puts(m <=> (m.map{|v| v+1}))
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 20
9
- version: 0.0.20
8
+ - 21
9
+ version: 0.0.21
10
10
  platform: ruby
11
11
  authors:
12
12
  - Paul Rivier
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-28 00:00:00 +02:00
17
+ date: 2011-09-29 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20