daitai 0.1.7 → 0.1.8

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: a0eef01b5a0d60007fb1c642b7c98e0044fa03b67e1eeb178018c8c76af73b92
4
- data.tar.gz: d6e31f441847c9783b97465e7a3431d23976518ad6e18a1e99c75f11ef73ce34
3
+ metadata.gz: 7b46501fd7f8f5f8728ce390c10bee1e01e270dd23d9138b4c789f3ef73ea91d
4
+ data.tar.gz: 0ef430632006a7529f577299882c0e8069d73e514015a8c94e043e58b478e163
5
5
  SHA512:
6
- metadata.gz: 8569685ae7960b9e15e9faf562dc9891bf42597581e4283a14bf92812995ce313a9644d9929bfe917a28f736477ee13bc7dd6811f94882fb4088e8ab6299b356
7
- data.tar.gz: 945ad40b819ef067d906e1da1e1ce52c4f927b30ce0f7a23d333c2bbca728efcaff282df0ee82e83cb06b7c7293e530fe5c991a9cead2127935ad4b880b1d032
6
+ metadata.gz: 31bc34d12c4d4ea1af384e1398d18437b063a864319a737f6f036b15cefdaa6e3a3224b02ff4e446a68cf9338bd4d94db1be8c64ba265baaf95f3aa6a54e1beb
7
+ data.tar.gz: c0dab7b6b0700d677e9e9e25e504b066dc22912ae8c8589c37216da969153d2e0a939e0db2474e2a282af30a6d2eac39d2d00074fdc60837b3544e12f221f136
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daitai (0.1.7)
4
+ daitai (0.1.8)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -34,13 +34,16 @@ $ gem install daitai
34
34
  * [abs](#abs-definition)
35
35
  * [add](#add-definition)
36
36
  * [all](#all-definition)
37
+ * [always](#always-definition)
37
38
  * [and](#and-definition)
38
39
  * [any](#any-definition)
39
40
  * [compose](#compose-definition)
40
41
  * [concat](#concat-definition)
41
42
  * [divide](#divide-definition)
42
43
  * [filter](#filter-definition)
44
+ * [flip](#flip-definition)
43
45
  * [head](#head-definition)
46
+ * [identity](#identity-definition)
44
47
  * [init](#init-definition)
45
48
  * [last](#last-definition)
46
49
  * [length](#length-definition)
@@ -63,6 +66,7 @@ $ gem install daitai
63
66
  * [subtract](#subtract-definition)
64
67
  * [sum](#sum-definition)
65
68
  * [tail](#tail-definition)
69
+ * [xor](#xor-definition)
66
70
 
67
71
  - - -
68
72
 
@@ -105,6 +109,21 @@ Daitai.all.(even, [2, 4, 7, 8]) # => false
105
109
 
106
110
  - - -
107
111
 
112
+ <h4 id='always-definition'>
113
+ <code>always :: a -> b -> a</code>
114
+ </h4>
115
+
116
+ Creates a function that always returns the provided value.
117
+
118
+ ```ruby
119
+ always_zero = Daitai.always.(0)
120
+ always_zero.(:one) # => 0
121
+ always_zero.(7, 8) # => 0
122
+ Daitai.map.(always_zero, [1, 2, 3, 4]) # => [0, 0, 0, 0]
123
+ ```
124
+
125
+ - - -
126
+
108
127
  <h4 id='and-definition'>
109
128
  <code>and :: Bool -> Bool -> Bool</code>
110
129
  </h4>
@@ -191,6 +210,20 @@ only_even.([1, 2, 3, 4]) # => [2, 4]
191
210
 
192
211
  - - -
193
212
 
213
+ <h4 id='flip-definition'>
214
+ <code>flip :: (a -> b -> … -> c) -> b -> a -> … -> c</code>
215
+ </h4>
216
+
217
+ Returns a copy of a function with reversed order of the first two arguments.
218
+
219
+ ```ruby
220
+ concat = ->(x, y) { x + y }
221
+ flipped_concat = Daitai.flip.(concat)
222
+ flipped_concat.("flip", "flop") # => "flopflip"
223
+ ```
224
+
225
+ - - -
226
+
194
227
  <h4 id='head-definition'>
195
228
  <code>head :: [a] -> a</code>
196
229
  </h4>
@@ -204,6 +237,19 @@ Daitai.head.("Ruby") # => "R"
204
237
 
205
238
  - - -
206
239
 
240
+ <h4 id='identity-definition'>
241
+ <code>identity :: a -> a</code>
242
+ </h4>
243
+
244
+ Returns exactly the provided value.
245
+
246
+ ```ruby
247
+ Daitai.identity.(1) # => 1
248
+ Daitai.identity.("Ruby") # => "Ruby"
249
+ ```
250
+
251
+ - - -
252
+
207
253
  <h4 id='init-definition'>
208
254
  <code>init :: [a] -> [a]</code>
209
255
  </h4>
@@ -516,6 +562,21 @@ Daitai.tail.("Ruby") # => "uby"
516
562
 
517
563
  - - -
518
564
 
565
+ <h4 id='xor-definition'>
566
+ <code>xor :: Bool -> Bool -> Bool</code>
567
+ </h4>
568
+
569
+ Boolean `xor` - returns `true` if only one of the arguments is true. Otherwise returs `false`.
570
+
571
+ ```ruby
572
+ Daitai.xor.(true, true) # => false
573
+ Daitai.xor.(true, false) # => true
574
+ Daitai.xor.(false, true) # => true
575
+ Daitai.xor.(false, false) # => false
576
+ ```
577
+
578
+ - - -
579
+
519
580
  ## Development
520
581
 
521
582
  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.
@@ -6,13 +6,16 @@ module Daitai
6
6
  extend Abs
7
7
  extend Add
8
8
  extend All
9
+ extend Always
9
10
  extend And
10
11
  extend Any
11
12
  extend Compose
12
13
  extend Concat
13
14
  extend Divide
14
15
  extend Filter
16
+ extend Flip
15
17
  extend Head
18
+ extend Identity
16
19
  extend Init
17
20
  extend Last
18
21
  extend Length
@@ -35,4 +38,5 @@ module Daitai
35
38
  extend Subtract
36
39
  extend Sum
37
40
  extend Tail
41
+ extend Xor
38
42
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Always
5
+ def always
6
+ lambda do |value|
7
+ ->(*) { value }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,7 +3,9 @@
3
3
  module Daitai
4
4
  module Concat
5
5
  def concat
6
- ->(x, y) { x + y }.curry
6
+ lambda do |x, y|
7
+ x + y
8
+ end.curry
7
9
  end
8
10
  end
9
11
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Flip
5
+ def flip
6
+ ->(function) { flip_arguments(function) }
7
+ end
8
+
9
+ private
10
+
11
+ def flip_arguments(function)
12
+ lambda do |first, second, *tail|
13
+ function.curry.(second, first, *tail)
14
+ end.curry
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Identity
5
+ def identity
6
+ ->(value) { value }
7
+ end
8
+ end
9
+ end
@@ -3,7 +3,9 @@
3
3
  module Daitai
4
4
  module Min
5
5
  def min
6
- ->(a, b) { a < b ? a : b }.curry
6
+ lambda do |a, b|
7
+ a < b ? a : b
8
+ end.curry
7
9
  end
8
10
  end
9
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daitai
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.8'
5
5
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Xor
5
+ def xor
6
+ lambda do |a, b|
7
+ a ^ b
8
+ end.curry
9
+ end
10
+ end
11
+ 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.7
4
+ version: 0.1.8
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-26 00:00:00.000000000 Z
11
+ date: 2018-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,13 +90,16 @@ files:
90
90
  - lib/daitai/abs.rb
91
91
  - lib/daitai/add.rb
92
92
  - lib/daitai/all.rb
93
+ - lib/daitai/always.rb
93
94
  - lib/daitai/and.rb
94
95
  - lib/daitai/any.rb
95
96
  - lib/daitai/compose.rb
96
97
  - lib/daitai/concat.rb
97
98
  - lib/daitai/divide.rb
98
99
  - lib/daitai/filter.rb
100
+ - lib/daitai/flip.rb
99
101
  - lib/daitai/head.rb
102
+ - lib/daitai/identity.rb
100
103
  - lib/daitai/init.rb
101
104
  - lib/daitai/last.rb
102
105
  - lib/daitai/length.rb
@@ -120,6 +123,7 @@ files:
120
123
  - lib/daitai/sum.rb
121
124
  - lib/daitai/tail.rb
122
125
  - lib/daitai/version.rb
126
+ - lib/daitai/xor.rb
123
127
  homepage: https://github.com/walerian777/daitai
124
128
  licenses:
125
129
  - MIT