daitai 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b46501fd7f8f5f8728ce390c10bee1e01e270dd23d9138b4c789f3ef73ea91d
4
- data.tar.gz: 0ef430632006a7529f577299882c0e8069d73e514015a8c94e043e58b478e163
3
+ metadata.gz: 0fd69882351f60ace283f0a3b53b28c651b8c086d567dae81e48554960e57079
4
+ data.tar.gz: 976b181231035ae58bb8ce47eaf20df7b4e9f3397646a679f5804e1e58b2d119
5
5
  SHA512:
6
- metadata.gz: 31bc34d12c4d4ea1af384e1398d18437b063a864319a737f6f036b15cefdaa6e3a3224b02ff4e446a68cf9338bd4d94db1be8c64ba265baaf95f3aa6a54e1beb
7
- data.tar.gz: c0dab7b6b0700d677e9e9e25e504b066dc22912ae8c8589c37216da969153d2e0a939e0db2474e2a282af30a6d2eac39d2d00074fdc60837b3544e12f221f136
6
+ metadata.gz: bea4f7410e064302f083afa6971c649d3fa5d8b3c941f18eb5cfc2b1d70ac0394fd9b8f37b2f604dddf628da2e965805942f26dcb8ecb323551b92746309cd97
7
+ data.tar.gz: 6512fac39887a98f87ccb95dccd1ba2d12c1799c53075e39870868a78a5b4f8dc2318ac8b776e2d50ffaca5439175f7d84f59adec38ff17d356f0f5de4c1eb0c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daitai (0.1.8)
4
+ daitai (0.1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -39,16 +39,22 @@ $ gem install daitai
39
39
  * [any](#any-definition)
40
40
  * [compose](#compose-definition)
41
41
  * [concat](#concat-definition)
42
+ * [dec](#dec-definition)
42
43
  * [divide](#divide-definition)
43
44
  * [filter](#filter-definition)
44
45
  * [flip](#flip-definition)
45
46
  * [head](#head-definition)
46
47
  * [identity](#identity-definition)
48
+ * [inc](#inc-definition)
47
49
  * [init](#init-definition)
50
+ * [is](#is-definition)
51
+ * [is_nil](#is_nil-definition)
48
52
  * [last](#last-definition)
49
53
  * [length](#length-definition)
50
54
  * [map](#map-definition)
51
55
  * [max](#max-definition)
56
+ * [mean](#mean-definition)
57
+ * [median](#median-definition)
52
58
  * [min](#min-definition)
53
59
  * [modulo](#modulo-definition)
54
60
  * [multiply](#multiply-definition)
@@ -181,6 +187,18 @@ Daitai.concat.("Szcz", "ecin") # => "Szczecin"
181
187
 
182
188
  - - -
183
189
 
190
+ <h4 id='dec-definition'>
191
+ <code>dec :: Numeric -> Numeric</code>
192
+ </h4>
193
+
194
+ Returns the decremented value of a provided number.
195
+
196
+ ```ruby
197
+ Daitai.dec.(7) # => 6
198
+ ```
199
+
200
+ - - -
201
+
184
202
  <h4 id='divide-definition'>
185
203
  <code>divide :: a -> a -> a</code>
186
204
  </h4>
@@ -250,6 +268,18 @@ Daitai.identity.("Ruby") # => "Ruby"
250
268
 
251
269
  - - -
252
270
 
271
+ <h4 id='inc-definition'>
272
+ <code>inc :: Numeric -> Numeric</code>
273
+ </h4>
274
+
275
+ Returns the incremented value of a provided number.
276
+
277
+ ```ruby
278
+ Daitai.inc.(7) # => 8
279
+ ```
280
+
281
+ - - -
282
+
253
283
  <h4 id='init-definition'>
254
284
  <code>init :: [a] -> [a]</code>
255
285
  </h4>
@@ -263,6 +293,40 @@ Daitai.init.("Ruby") # => "Rub"
263
293
 
264
294
  - - -
265
295
 
296
+ <h4 id='is-definition'>
297
+ <code>is :: Constant -> a -> Bool</code>
298
+ </h4>
299
+
300
+ Checks if an argument is an instance of the provided type.
301
+
302
+ ```ruby
303
+ Daitai.is.(Numeric, 7.77) # => true
304
+ Daitai.is.(Float, 7.77) # => true
305
+ Daitai.is.(String, "Ruby") # => true
306
+ Daitai.is.(Regexp, /hello/) # => true
307
+
308
+ Daitai.is.(Hash, {}) # => true
309
+ Daitai.is.(Enumerable, {}) # => true
310
+ Daitai.is.(Object, {}) # => true
311
+ Daitai.is.(Numeric, {}) # => false
312
+ ```
313
+
314
+ - - -
315
+
316
+ <h4 id='is_nil-definition'>
317
+ <code>is_nil :: a -> Bool</code>
318
+ </h4>
319
+
320
+ Checks if an argument is a `nil`.
321
+
322
+ ```ruby
323
+ Daitai.is_nil.(nil) # => true
324
+ Daitai.is_nil.(false) # => false
325
+ Daitai.is_nil.(0) # => false
326
+ ```
327
+
328
+ - - -
329
+
266
330
  <h4 id='last-definition'>
267
331
  <code>last :: [a] -> a</code>
268
332
  </h4>
@@ -306,6 +370,34 @@ increment.([1, 2, 3, 4]) # => [2, 3, 4, 5]
306
370
 
307
371
  - - -
308
372
 
373
+ <h4 id='mean-definition'>
374
+ <code>mean :: [Numeric] -> Float</code>
375
+ </h4>
376
+
377
+ Returns the mean of a list.
378
+
379
+ ```ruby
380
+ Daitai.mean.([3, 4.5, 9]) # => 5.5
381
+ Daitai.mean.([6, 7]) # => 6.5
382
+ Daitai.mean.([]) # => NaN
383
+ ```
384
+
385
+ - - -
386
+
387
+ <h4 id='median-definition'>
388
+ <code>median :: [Numeric] -> Float</code>
389
+ </h4>
390
+
391
+ Returns the median of a list.
392
+
393
+ ```ruby
394
+ Daitai.median.([3.14, 4.5, 7.77]) # => 4.5
395
+ Daitai.median.([6, 7]) # => 6.5
396
+ Daitai.median.([]) # => NaN
397
+ ```
398
+
399
+ - - -
400
+
309
401
  <h4 id='max-definition'>
310
402
  <code>max :: a -> a -> a</code>
311
403
  </h4>
@@ -11,16 +11,22 @@ module Daitai
11
11
  extend Any
12
12
  extend Compose
13
13
  extend Concat
14
+ extend Dec
14
15
  extend Divide
15
16
  extend Filter
16
17
  extend Flip
17
18
  extend Head
18
19
  extend Identity
20
+ extend Inc
19
21
  extend Init
22
+ extend Is
23
+ extend IsNil
20
24
  extend Last
21
25
  extend Length
22
26
  extend Map
23
27
  extend Max
28
+ extend Mean
29
+ extend Median
24
30
  extend Min
25
31
  extend Modulo
26
32
  extend Multiply
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Dec
5
+ def dec
6
+ add.(-1)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Inc
5
+ def inc
6
+ add.(1)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Is
5
+ def is
6
+ ->(type, value) { value.is_a?(type) }.curry
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module IsNil
5
+ def is_nil # rubocop:disable Naming/PredicateName
6
+ is.(NilClass)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Mean
5
+ def mean
6
+ ->(list) { sum.(list).to_f / length.(list) }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Median
5
+ def median
6
+ lambda do |list|
7
+ list_length = length.(list)
8
+ return Float::NAN if list_length.zero?
9
+
10
+ sorted_list = sort.(list)
11
+ (sorted_list[(list_length - 1) / 2] + sorted_list[list_length / 2]) / 2.0
12
+ end
13
+ end
14
+ end
15
+ end
@@ -3,7 +3,7 @@
3
3
  module Daitai
4
4
  module Product
5
5
  def product
6
- Daitai.reduce.(:*, 1)
6
+ reduce.(:*, 1)
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  module Daitai
4
4
  module Sum
5
5
  def sum
6
- Daitai.reduce.(:+, 0)
6
+ reduce.(:+, 0)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daitai
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.9'
5
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.8
4
+ version: 0.1.9
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-03-28 00:00:00.000000000 Z
11
+ date: 2018-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,16 +95,22 @@ files:
95
95
  - lib/daitai/any.rb
96
96
  - lib/daitai/compose.rb
97
97
  - lib/daitai/concat.rb
98
+ - lib/daitai/dec.rb
98
99
  - lib/daitai/divide.rb
99
100
  - lib/daitai/filter.rb
100
101
  - lib/daitai/flip.rb
101
102
  - lib/daitai/head.rb
102
103
  - lib/daitai/identity.rb
104
+ - lib/daitai/inc.rb
103
105
  - lib/daitai/init.rb
106
+ - lib/daitai/is.rb
107
+ - lib/daitai/is_nil.rb
104
108
  - lib/daitai/last.rb
105
109
  - lib/daitai/length.rb
106
110
  - lib/daitai/map.rb
107
111
  - lib/daitai/max.rb
112
+ - lib/daitai/mean.rb
113
+ - lib/daitai/median.rb
108
114
  - lib/daitai/min.rb
109
115
  - lib/daitai/modulo.rb
110
116
  - lib/daitai/multiply.rb