daitai 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.
- checksums.yaml +5 -5
- data/.rubocop.yml +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +42 -4
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/daitai.gemspec +2 -0
- data/lib/daitai.rb +4 -0
- data/lib/daitai/abs.rb +2 -0
- data/lib/daitai/add.rb +2 -0
- data/lib/daitai/all.rb +2 -0
- data/lib/daitai/and.rb +2 -0
- data/lib/daitai/any.rb +2 -0
- data/lib/daitai/compose.rb +2 -0
- data/lib/daitai/divide.rb +2 -0
- data/lib/daitai/filter.rb +2 -0
- data/lib/daitai/map.rb +2 -0
- data/lib/daitai/modulo.rb +2 -0
- data/lib/daitai/multiply.rb +2 -0
- data/lib/daitai/negate.rb +2 -0
- data/lib/daitai/not.rb +2 -0
- data/lib/daitai/or.rb +2 -0
- data/lib/daitai/pipe.rb +2 -0
- data/lib/daitai/product.rb +9 -0
- data/lib/daitai/reduce.rb +2 -0
- data/lib/daitai/signum.rb +2 -0
- data/lib/daitai/sort.rb +2 -0
- data/lib/daitai/subtract.rb +2 -0
- data/lib/daitai/sum.rb +9 -0
- data/lib/daitai/version.rb +3 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f12e1a03e40649b94f4c292d9f28c595b7085d92
|
4
|
+
data.tar.gz: 55173f99bfbcc084684470cd8adfb7ef8c63a02f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 877c971038097f02e7d304a8407ff1fd6e91edc7ecf118d1e337ce3b82a536b662c6bc56a2b4c48d110b6105ad65d53551290c7d8742f74a5f5f513612a000d1
|
7
|
+
data.tar.gz: 576431a89a934202e58ac1ba3f5ac2cae24c6cdaa7973126399aa43e54d628503907ffb7fd68cc59d58258a073addbd459826acbfebd41a96e602d8f167e4f3e
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -46,10 +46,12 @@ $ gem install daitai
|
|
46
46
|
* [not](#not-definition)
|
47
47
|
* [or](#or-definition)
|
48
48
|
* [pipe](#pipe-definition)
|
49
|
+
* [product](#product-definition)
|
49
50
|
* [reduce](#reduce-definition)
|
50
51
|
* [signum](#signum-definition)
|
51
52
|
* [sort](#sort-definition)
|
52
53
|
* [subtract](#subtract-definition)
|
54
|
+
* [sum](#sum-definition)
|
53
55
|
|
54
56
|
- - -
|
55
57
|
|
@@ -157,6 +159,9 @@ Returns a list of all elements that satisfy the predicate.
|
|
157
159
|
```ruby
|
158
160
|
greater_than_two = ->(x) { x > 2 }
|
159
161
|
Daitai.filter.(greater_than_two, [1, 2, 3, 4]) # => [3, 4]
|
162
|
+
|
163
|
+
only_even = Daitai.filter.(->(x) { x % 2 == 0 })
|
164
|
+
only_even.([1, 2, 3, 4]) # => [2, 4]
|
160
165
|
```
|
161
166
|
|
162
167
|
- - -
|
@@ -170,6 +175,9 @@ Applies the function to all elements of the list and returns a new list of the r
|
|
170
175
|
```ruby
|
171
176
|
triple = ->(x) { x * 3 }
|
172
177
|
Daitai.map.(triple, [1, 2, 3, 4]) # => [3, 6, 9, 12]
|
178
|
+
|
179
|
+
increment = Daitai.map.(->(x) { x + 1 })
|
180
|
+
increment.([1, 2, 3, 4]) # => [2, 3, 4, 5]
|
173
181
|
```
|
174
182
|
|
175
183
|
- - -
|
@@ -199,7 +207,7 @@ Daitai.multiply.(4, 3) # => 12
|
|
199
207
|
- - -
|
200
208
|
|
201
209
|
<h4 id='negate-definition'>
|
202
|
-
<code>negate ::
|
210
|
+
<code>negate :: a -> a</code>
|
203
211
|
</h4>
|
204
212
|
|
205
213
|
Unary negation - returns a negated value of the argument.
|
@@ -256,6 +264,18 @@ f.(10) # => 102
|
|
256
264
|
|
257
265
|
- - -
|
258
266
|
|
267
|
+
<h4 id='product-definition'>
|
268
|
+
<code>product :: [a] -> a</code>
|
269
|
+
</h4>
|
270
|
+
|
271
|
+
Calculates the product of all elements of a list.
|
272
|
+
|
273
|
+
```ruby
|
274
|
+
Daitai.sum.([1, 2, 3, 4]) # => 24
|
275
|
+
```
|
276
|
+
|
277
|
+
- - -
|
278
|
+
|
259
279
|
<h4 id='reduce-definition'>
|
260
280
|
<code>reduce :: (a -> b -> a) -> a -> [b] -> a</code>
|
261
281
|
</h4>
|
@@ -263,8 +283,11 @@ f.(10) # => 102
|
|
263
283
|
Reduces the list using the function, from left to right, using the accumulator.
|
264
284
|
|
265
285
|
```ruby
|
266
|
-
|
267
|
-
Daitai.reduce.(
|
286
|
+
add = ->(x, y) { x + y }
|
287
|
+
Daitai.reduce.(add, 0, [1, 2, 3, 4]) # => 10
|
288
|
+
|
289
|
+
concat = Daitai.reduce.(add, "")
|
290
|
+
concat.(%w[l a m b d a]) # => "lambda"
|
268
291
|
```
|
269
292
|
|
270
293
|
- - -
|
@@ -284,7 +307,7 @@ Daitai.signum.(-8) # => -1
|
|
284
307
|
- - -
|
285
308
|
|
286
309
|
<h4 id='sort-definition'>
|
287
|
-
<code>sort :: (a -> a ->
|
310
|
+
<code>sort :: (a -> a -> Numeric) -> [a] -> [a]</code>
|
288
311
|
</h4>
|
289
312
|
|
290
313
|
Returns a sorted copy of the list according to the specified comparator function.
|
@@ -292,6 +315,9 @@ Returns a sorted copy of the list according to the specified comparator function
|
|
292
315
|
```ruby
|
293
316
|
diff = ->(x, y) { x - y }
|
294
317
|
Daitai.sort.(diff, [2, 1, 4, 3]) # => [1, 2, 3, 4]
|
318
|
+
|
319
|
+
sort_by_length = Daitai.sort.(->(x, y) { x.length - y.length })
|
320
|
+
sort_by_length.(%w[haskell ruby elixir]) # => ["ruby", "elixir", "haskell"]
|
295
321
|
```
|
296
322
|
|
297
323
|
- - -
|
@@ -308,6 +334,18 @@ Daitai.subtract.(9, 4) # => 5
|
|
308
334
|
|
309
335
|
- - -
|
310
336
|
|
337
|
+
<h4 id='sum-definition'>
|
338
|
+
<code>sum :: [a] -> a</code>
|
339
|
+
</h4>
|
340
|
+
|
341
|
+
Calculates the sum of all elements of a list.
|
342
|
+
|
343
|
+
```ruby
|
344
|
+
Daitai.sum.([1, 2, 3, 4]) # => 10
|
345
|
+
```
|
346
|
+
|
347
|
+
- - -
|
348
|
+
|
311
349
|
## Development
|
312
350
|
|
313
351
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/daitai.gemspec
CHANGED
data/lib/daitai.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
Dir["#{__dir__}/daitai/*"].each { |file| require file }
|
2
4
|
|
3
5
|
module Daitai
|
@@ -16,8 +18,10 @@ module Daitai
|
|
16
18
|
extend Not
|
17
19
|
extend Or
|
18
20
|
extend Pipe
|
21
|
+
extend Product
|
19
22
|
extend Reduce
|
20
23
|
extend Signum
|
21
24
|
extend Sort
|
22
25
|
extend Subtract
|
26
|
+
extend Sum
|
23
27
|
end
|
data/lib/daitai/abs.rb
CHANGED
data/lib/daitai/add.rb
CHANGED
data/lib/daitai/all.rb
CHANGED
data/lib/daitai/and.rb
CHANGED
data/lib/daitai/any.rb
CHANGED
data/lib/daitai/compose.rb
CHANGED
data/lib/daitai/divide.rb
CHANGED
data/lib/daitai/filter.rb
CHANGED
data/lib/daitai/map.rb
CHANGED
data/lib/daitai/modulo.rb
CHANGED
data/lib/daitai/multiply.rb
CHANGED
data/lib/daitai/negate.rb
CHANGED
data/lib/daitai/not.rb
CHANGED
data/lib/daitai/or.rb
CHANGED
data/lib/daitai/pipe.rb
CHANGED
data/lib/daitai/reduce.rb
CHANGED
data/lib/daitai/signum.rb
CHANGED
data/lib/daitai/sort.rb
CHANGED
data/lib/daitai/subtract.rb
CHANGED
data/lib/daitai/sum.rb
ADDED
data/lib/daitai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daitai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Walerian Sobczak
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,10 +102,12 @@ files:
|
|
102
102
|
- lib/daitai/not.rb
|
103
103
|
- lib/daitai/or.rb
|
104
104
|
- lib/daitai/pipe.rb
|
105
|
+
- lib/daitai/product.rb
|
105
106
|
- lib/daitai/reduce.rb
|
106
107
|
- lib/daitai/signum.rb
|
107
108
|
- lib/daitai/sort.rb
|
108
109
|
- lib/daitai/subtract.rb
|
110
|
+
- lib/daitai/sum.rb
|
109
111
|
- lib/daitai/version.rb
|
110
112
|
homepage: https://github.com/walerian777/daitai
|
111
113
|
licenses:
|
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
129
|
version: '0'
|
128
130
|
requirements: []
|
129
131
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
132
|
+
rubygems_version: 2.2.2
|
131
133
|
signing_key:
|
132
134
|
specification_version: 4
|
133
135
|
summary: A functional library for Ruby.
|