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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ff5f9a0398ddd5b9986a5b49e7e4f24d4bf2bd91956c8412ec30248c202e4ddc
4
- data.tar.gz: f04937930985840d55fa23360e40718c6925ca864b55a7e248e3e84ec585ee1e
2
+ SHA1:
3
+ metadata.gz: f12e1a03e40649b94f4c292d9f28c595b7085d92
4
+ data.tar.gz: 55173f99bfbcc084684470cd8adfb7ef8c63a02f
5
5
  SHA512:
6
- metadata.gz: 9582ec942bba4201b0d6d20d94956dd0653fa48576629cef90f96296466067f860499ffdde347827835a1e87b0b8fc0872c26592c85eb28f29263646fdd153ce
7
- data.tar.gz: 93dc0089b5777f2bc1b8fd5387178e2a96df629b496c5d91696fdc43c232633ea20bdaa30cbb4524fd06b762e7c025a718b73e5948f6fea55b959c97aa267630
6
+ metadata.gz: 877c971038097f02e7d304a8407ff1fd6e91edc7ecf118d1e337ce3b82a536b662c6bc56a2b4c48d110b6105ad65d53551290c7d8742f74a5f5f513612a000d1
7
+ data.tar.gz: 576431a89a934202e58ac1ba3f5ac2cae24c6cdaa7973126399aa43e54d628503907ffb7fd68cc59d58258a073addbd459826acbfebd41a96e602d8f167e4f3e
@@ -1,6 +1,9 @@
1
1
  Style/LambdaCall:
2
2
  EnforcedStyle: braces
3
3
 
4
+ Style/FrozenStringLiteralComment:
5
+ EnforcedStyle: always
6
+
4
7
  Style/Documentation:
5
8
  Enabled: false
6
9
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daitai (0.1.2)
4
+ daitai (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 :: Bool -> Bool</code>
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
- sum = ->(x, y) { x + y }
267
- Daitai.reduce.(sum, 0, [1, 2, 3, 4]) # => 10
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 -> Number) -> [a] -> [a]</code>
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'daitai'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('../lib', __FILE__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'daitai/version'
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Abs
3
5
  def abs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Add
3
5
  def add
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module All
3
5
  def all
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module And
3
5
  def and
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Any
3
5
  def any
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Compose
3
5
  def compose
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Divide
3
5
  def divide
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Filter
3
5
  def filter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Map
3
5
  def map
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Modulo
3
5
  def modulo
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Multiply
3
5
  def multiply
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Negate
3
5
  def negate
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Not
3
5
  def not
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Or
3
5
  def or
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Pipe
3
5
  def pipe
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Product
5
+ def product
6
+ Daitai.reduce.(:*, 1)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Reduce
3
5
  def reduce
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Signum
3
5
  def signum
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Sort
3
5
  def sort
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
4
  module Subtract
3
5
  def subtract
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Sum
5
+ def sum
6
+ Daitai.reduce.(:+, 0)
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Daitai
2
- VERSION = '0.1.2'.freeze
4
+ VERSION = '0.1.3'.freeze
3
5
  end
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.2
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-02-25 00:00:00.000000000 Z
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.7.3
132
+ rubygems_version: 2.2.2
131
133
  signing_key:
132
134
  specification_version: 4
133
135
  summary: A functional library for Ruby.