raskell 0.1.2 → 0.1.3

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.
@@ -1,188 +1,189 @@
1
1
  require 'singleton'
2
2
 
3
-
4
- class Foldl
5
-
6
- alias_method :standard_ruby_kind_of?, :kind_of?
7
-
8
- def kind_of?(clazz)
9
- [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
10
- end
11
-
12
- def initialize(*monoids) # must be [fn, unit] pair, a monoid
13
- @monoids = monoids
14
- self
15
- end
16
-
17
- def monoids
18
- @monoids
19
- end
20
-
21
- def *(lamb)
22
- ->(x) { self.( lamb.( x ) ) }
23
- end
24
-
25
- def |(lamb)
26
- ->(x) { lamb.( self.( x ) ) }
27
- end
28
-
29
- def <<(val)
30
- self.(val.())
31
- end
32
-
33
- def >>(lamb)
34
- lamb.(self)
35
- end
36
-
37
- def +(foldl)
38
- if foldl.kind_of?(Foldl)
39
- Foldl.new(*(self.monoids + foldl.monoids))
40
- else
41
- raise "Cannot add two non-folds together"
3
+ module System
4
+ class Foldl
5
+
6
+ alias_method :standard_ruby_kind_of?, :kind_of?
7
+
8
+ def kind_of?(clazz)
9
+ [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
42
10
  end
43
- end
44
-
45
- def call(stream)
46
- if stream.respond_to?(:to_stream)
47
- if @monoids.length > 1
48
- fn = ->(acc, el) { F.zip_with.(F.apply_fn).(@monoids.map(&:first), acc, @monoids.map {|x| el }).to_a }
49
- F.foldleft.(fn, @monoids.map(&:last)).(stream).to_a
50
- else
51
- F.foldleft.(*@monoids.first).(stream)
52
- end
53
- else
54
- raise "Cannot call Foldl on an object that does not have to_stream defined."
55
- end
56
- end
57
-
58
- @@foldl = ->(f,u) { Foldl.new([f,u])}
59
- def self.foldl
60
- @@foldl
11
+
12
+ def initialize(*monoids) # must be [fn, unit] pair, a monoid
13
+ @monoids = monoids
14
+ self
15
+ end
16
+
17
+ def monoids
18
+ @monoids
19
+ end
20
+
21
+ def *(lamb)
22
+ ->(x) { self.( lamb.( x ) ) }
23
+ end
24
+
25
+ def |(lamb)
26
+ ->(x) { lamb.( self.( x ) ) }
27
+ end
28
+
29
+ def <<(val)
30
+ self.(val.())
31
+ end
32
+
33
+ def >>(lamb)
34
+ lamb.(self)
35
+ end
36
+
37
+ def +(foldl)
38
+ if foldl.kind_of?(Foldl)
39
+ Foldl.new(*(self.monoids + foldl.monoids))
40
+ else
41
+ raise "Cannot add two non-folds together"
42
+ end
43
+ end
44
+
45
+ def call(stream)
46
+ if stream.respond_to?(:to_stream)
47
+ if @monoids.length > 1
48
+ fn = ->(acc, el) { F.zip_with.(F.apply_fn).(@monoids.map(&:first), acc, @monoids.map {|x| el }).to_a }
49
+ F.foldleft.(fn, @monoids.map(&:last)).(stream).to_a
50
+ else
51
+ F.foldleft.(*@monoids.first).(stream)
52
+ end
53
+ else
54
+ raise "Cannot call Foldl on an object that does not have to_stream defined."
55
+ end
56
+ end
57
+
58
+ @@foldl = ->(f,u) { Foldl.new([f,u])}
59
+ def self.foldl
60
+ @@foldl
61
+ end
61
62
  end
62
- end
63
-
64
- class F
65
- include Singleton
66
- end
67
-
68
- F.define_singleton_method(:foldl) { Foldl.foldl }
69
-
70
- class Scanl
71
- alias_method :standard_ruby_kind_of?, :kind_of?
72
-
73
- def kind_of?(clazz)
74
- [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
75
- end
76
-
77
- def initialize(*monoids) # must be [fn, unit] pair, a monoid
78
- @monoids = monoids
79
- self
80
- end
81
-
82
- def monoids
83
- @monoids
84
- end
85
-
86
- def *(lamb)
87
- ->(x) { self.( lamb.( x ) ) }
88
- end
89
-
90
- def |(lamb)
91
- ->(x) { lamb.( self.( x ) ) }
92
- end
93
-
94
- def <<(val)
95
- self.(val.())
96
- end
97
-
98
- def >>(lamb)
99
- lamb.(self)
100
- end
101
-
102
- def +(scanl)
103
- if scanl.kind_of?(Scanl)
104
- Scanl.new(*(self.monoids + scanl.monoids))
105
- else
106
- raise "Cannot add two non-folds together"
63
+
64
+ class F
65
+ include Singleton
66
+ end
67
+
68
+ F.define_singleton_method(:foldl) { Foldl.foldl }
69
+
70
+ class Scanl
71
+ alias_method :standard_ruby_kind_of?, :kind_of?
72
+
73
+ def kind_of?(clazz)
74
+ [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
107
75
  end
108
- end
109
-
110
- def call(stream)
111
- if stream.respond_to?(:to_stream)
112
- if @monoids.length > 1
113
- fn = ->(acc, el) { F.zip_with.(F.apply_fn).(@monoids.map(&:first), acc, @monoids.map {|x| el }).to_a }
114
- F.scanleft.(fn, @monoids.map(&:last)).(stream)
115
- else
116
- F.scanleft.(*@monoids.first).(stream)
117
- end
118
- else
119
- raise "Cannot call Foldl on an object that does not have to_stream defined."
120
- end
121
- end
122
-
123
- @@scanl = ->(f,u) { Scanl.new([f,u])}
124
- def self.scanl
125
- @@scanl
76
+
77
+ def initialize(*monoids) # must be [fn, unit] pair, a monoid
78
+ @monoids = monoids
79
+ self
80
+ end
81
+
82
+ def monoids
83
+ @monoids
84
+ end
85
+
86
+ def *(lamb)
87
+ ->(x) { self.( lamb.( x ) ) }
88
+ end
89
+
90
+ def |(lamb)
91
+ ->(x) { lamb.( self.( x ) ) }
92
+ end
93
+
94
+ def <<(val)
95
+ self.(val.())
96
+ end
97
+
98
+ def >>(lamb)
99
+ lamb.(self)
100
+ end
101
+
102
+ def +(scanl)
103
+ if scanl.kind_of?(Scanl)
104
+ Scanl.new(*(self.monoids + scanl.monoids))
105
+ else
106
+ raise "Cannot add two non-folds together"
107
+ end
108
+ end
109
+
110
+ def call(stream)
111
+ if stream.respond_to?(:to_stream)
112
+ if @monoids.length > 1
113
+ fn = ->(acc, el) { F.zip_with.(F.apply_fn).(@monoids.map(&:first), acc, @monoids.map {|x| el }).to_a }
114
+ F.scanleft.(fn, @monoids.map(&:last)).(stream)
115
+ else
116
+ F.scanleft.(*@monoids.first).(stream)
117
+ end
118
+ else
119
+ raise "Cannot call Foldl on an object that does not have to_stream defined."
120
+ end
121
+ end
122
+
123
+ @@scanl = ->(f,u) { Scanl.new([f,u])}
124
+ def self.scanl
125
+ @@scanl
126
+ end
126
127
  end
127
- end
128
- F.define_singleton_method(:scanl) { Scanl.scanl }
129
-
130
-
131
- class Mapl
132
- alias_method :standard_ruby_kind_of?, :kind_of?
133
-
134
- def kind_of?(clazz)
135
- [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
136
- end
137
-
138
- def initialize(*functions)
139
- @functions = functions
140
- self
141
- end
142
-
143
- def functions
144
- @functions
145
- end
146
-
147
- def *(lamb)
148
- ->(x) { self.( lamb.( x ) ) }
149
- end
150
-
151
- def |(lamb)
152
- ->(x) { lamb.( self.( x ) ) }
153
- end
154
-
155
- def <<(val)
156
- self.(val.())
157
- end
158
-
159
- def >>(lamb)
160
- lamb.(self)
161
- end
162
-
163
- def +(mapl)
164
- if mapl.kind_of?(Mapl)
165
- Mapl.new(*(self.functions + mapl.functions))
166
- else
167
- raise "Cannot add two non-maps together"
128
+ F.define_singleton_method(:scanl) { Scanl.scanl }
129
+
130
+
131
+ class Mapl
132
+ alias_method :standard_ruby_kind_of?, :kind_of?
133
+
134
+ def kind_of?(clazz)
135
+ [Proc].include?(clazz) || standard_ruby_kind_of?(clazz)
168
136
  end
169
- end
170
-
171
- def call(stream)
172
- if stream.respond_to?(:to_stream)
173
- if @functions.length > 1
174
- F.mapleft.(@functions).(stream)
175
- else
176
- F.mapleft.(@functions.first).(stream)
177
- end
178
- else
179
- raise "Cannot call Mapl on an object that does not have to_stream defined."
180
- end
181
- end
182
-
183
- @@map = ->(f) { Mapl.new(f)}
184
- def self.map
185
- @@map
137
+
138
+ def initialize(*functions)
139
+ @functions = functions
140
+ self
141
+ end
142
+
143
+ def functions
144
+ @functions
145
+ end
146
+
147
+ def *(lamb)
148
+ ->(x) { self.( lamb.( x ) ) }
149
+ end
150
+
151
+ def |(lamb)
152
+ ->(x) { lamb.( self.( x ) ) }
153
+ end
154
+
155
+ def <<(val)
156
+ self.(val.())
157
+ end
158
+
159
+ def >>(lamb)
160
+ lamb.(self)
161
+ end
162
+
163
+ def +(mapl)
164
+ if mapl.kind_of?(Mapl)
165
+ Mapl.new(*(self.functions + mapl.functions))
166
+ else
167
+ raise "Cannot add two non-maps together"
168
+ end
169
+ end
170
+
171
+ def call(stream)
172
+ if stream.respond_to?(:to_stream)
173
+ if @functions.length > 1
174
+ F.mapleft.(@functions).(stream)
175
+ else
176
+ F.mapleft.(@functions.first).(stream)
177
+ end
178
+ else
179
+ raise "Cannot call Mapl on an object that does not have to_stream defined."
180
+ end
181
+ end
182
+
183
+ @@map = ->(f) { Mapl.new(f)}
184
+ def self.map
185
+ @@map
186
+ end
186
187
  end
187
- end
188
- F.define_singleton_method(:map) { Mapl.map }
188
+ F.define_singleton_method(:map) { Mapl.map }
189
+ end
@@ -1,3 +1,3 @@
1
1
  module Raskell
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raskell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kian Wilcox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Functional and Concatenative Programming With Streams in Ruby
14
14
  email: