daitai 0.1.11 → 0.1.12
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 +4 -4
- data/.travis.yml +3 -1
- data/Gemfile.lock +1 -1
- data/README.md +64 -0
- data/lib/daitai.rb +4 -0
- data/lib/daitai/functions/comparator.rb +2 -2
- data/lib/daitai/functions/cond.rb +23 -0
- data/lib/daitai/functions/equals.rb +11 -0
- data/lib/daitai/functions/false.rb +9 -0
- data/lib/daitai/functions/true.rb +9 -0
- data/lib/daitai/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1939017ecba29ca4fe6e6ee9a5773e51453a236b9fc688a8a90418f7317958db
|
4
|
+
data.tar.gz: a1d08cbcac87cfd8689652a391380e7b857c7a617aca0edcb2a3b8dee79e56d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1a1b81055ddebb8ad11e8fef26f168c4c16074066a2b26d51fcccd1c4df17ab9e76d1959392dd119b8ce71cb733080cf42081b90185d534832c8dbec25ad3c
|
7
|
+
data.tar.gz: 2fc218befeb82b84827a1dd303679fa238bd758125d4ba080838bcd30b0a899512cd00675ad16091d64127712042aa975f15ce075f0777e6af5ddf4180b72ece
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -40,8 +40,11 @@ $ gem install daitai
|
|
40
40
|
* [comparator](#comparator-definition)
|
41
41
|
* [compose](#compose-definition)
|
42
42
|
* [concat](#concat-definition)
|
43
|
+
* [cond](#cond-definition)
|
43
44
|
* [dec](#dec-definition)
|
44
45
|
* [divide](#divide-definition)
|
46
|
+
* [equals](#equals-definition)
|
47
|
+
* [false](#false-definition)
|
45
48
|
* [filter](#filter-definition)
|
46
49
|
* [flip](#flip-definition)
|
47
50
|
* [head](#head-definition)
|
@@ -75,6 +78,7 @@ $ gem install daitai
|
|
75
78
|
* [sum](#sum-definition)
|
76
79
|
* [tail](#tail-definition)
|
77
80
|
* [tap](#tap-definition)
|
81
|
+
* [true](#true-definition)
|
78
82
|
* [xor](#xor-definition)
|
79
83
|
|
80
84
|
- - -
|
@@ -209,6 +213,26 @@ Daitai.concat.("Szcz", "ecin") # => "Szczecin"
|
|
209
213
|
|
210
214
|
- - -
|
211
215
|
|
216
|
+
<h4 id='cond-definition'>
|
217
|
+
<code>cond :: [[(*… → Bool), (*… → *)]] → (*… → *)</code>
|
218
|
+
</h4>
|
219
|
+
|
220
|
+
Takes a list of pairs consisted of a predicate and a transformer and returns a function which finds the first passing predicate and evaluates the corresponding transformer. Returns a `nil` if there is no matching predicate.
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
function = Daitai.cond.(
|
224
|
+
[Daitai.is.(String), Daitai.always.("It's a String!")],
|
225
|
+
[Daitai.is.(Symbol), Daitai.always.("It's a Symbol!")],
|
226
|
+
[Daitai.true, ->(unknown) { "I don't know what #{unknown} is."}]
|
227
|
+
)
|
228
|
+
|
229
|
+
function.("いただきます") # => "It's a String!"
|
230
|
+
function.(:env) # => "It's a Symbol!"
|
231
|
+
function.(3.14) # => "I don't know what 3.14 is."
|
232
|
+
```
|
233
|
+
|
234
|
+
- - -
|
235
|
+
|
212
236
|
<h4 id='dec-definition'>
|
213
237
|
<code>dec :: Numeric -> Numeric</code>
|
214
238
|
</h4>
|
@@ -233,6 +257,33 @@ Daitai.divide.(18, 6) # => 3
|
|
233
257
|
|
234
258
|
- - -
|
235
259
|
|
260
|
+
<h4 id='equals-definition'>
|
261
|
+
<code>equals :: a -> b -> Bool</code>
|
262
|
+
</h4>
|
263
|
+
|
264
|
+
Returns `true` if both arguments are equal. Otherwise returns `false`.
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
Daitai.equals.(7, 7) # => true
|
268
|
+
Daitai.equals.('7', 7) # => false
|
269
|
+
Daitai.equals.(%w[a b c], %w[a b c]) # => true
|
270
|
+
```
|
271
|
+
|
272
|
+
- - -
|
273
|
+
|
274
|
+
<h4 id='false-definition'>
|
275
|
+
<code>false :: * -> Bool</code>
|
276
|
+
</h4>
|
277
|
+
|
278
|
+
Returns a function that ignores all arguments and always returns `false`.
|
279
|
+
|
280
|
+
```ruby
|
281
|
+
Daitai.false.() # => false
|
282
|
+
Daitai.false.(1, 2, 3) # => false
|
283
|
+
```
|
284
|
+
|
285
|
+
- - -
|
286
|
+
|
236
287
|
<h4 id='filter-definition'>
|
237
288
|
<code>filter :: (a -> Bool) -> [a] -> [a]</code>
|
238
289
|
</h4>
|
@@ -708,6 +759,19 @@ Daitai.tap.(logger, 7)
|
|
708
759
|
|
709
760
|
- - -
|
710
761
|
|
762
|
+
<h4 id='true-definition'>
|
763
|
+
<code>true :: * → Bool</code>
|
764
|
+
</h4>
|
765
|
+
|
766
|
+
Returns a function that ignores all arguments and always returns `true`.
|
767
|
+
|
768
|
+
```ruby
|
769
|
+
Daitai.true.() # => true
|
770
|
+
Daitai.true.(1, 2, 3) # => true
|
771
|
+
```
|
772
|
+
|
773
|
+
- - -
|
774
|
+
|
711
775
|
<h4 id='xor-definition'>
|
712
776
|
<code>xor :: Bool -> Bool -> Bool</code>
|
713
777
|
</h4>
|
data/lib/daitai.rb
CHANGED
@@ -14,8 +14,11 @@ module Daitai
|
|
14
14
|
extend Comparator
|
15
15
|
extend Compose
|
16
16
|
extend Concat
|
17
|
+
extend Cond
|
17
18
|
extend Dec
|
18
19
|
extend Divide
|
20
|
+
extend Equals
|
21
|
+
extend False
|
19
22
|
extend Filter
|
20
23
|
extend Flip
|
21
24
|
extend Head
|
@@ -49,5 +52,6 @@ module Daitai
|
|
49
52
|
extend Sum
|
50
53
|
extend Tail
|
51
54
|
extend Tap
|
55
|
+
extend True
|
52
56
|
extend Xor
|
53
57
|
end
|
@@ -4,13 +4,13 @@ module Daitai
|
|
4
4
|
module Comparator
|
5
5
|
def comparator
|
6
6
|
lambda do |predicate|
|
7
|
-
->(a, b) {
|
7
|
+
->(a, b) { evaluate_comparator(predicate, a, b) }
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def
|
13
|
+
def evaluate_comparator(predicate, a, b)
|
14
14
|
return -1 if predicate.(a, b)
|
15
15
|
return 1 if predicate.(b, a)
|
16
16
|
0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Daitai
|
4
|
+
module Cond
|
5
|
+
def cond
|
6
|
+
->(*pairs) { evaluate_cond(pairs) }
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def evaluate_cond(pairs)
|
12
|
+
lambda do |*arguments|
|
13
|
+
result = nil
|
14
|
+
|
15
|
+
pairs.each do |(predicate, transformer)|
|
16
|
+
break result = transformer.(*arguments) if predicate.(*arguments)
|
17
|
+
end
|
18
|
+
|
19
|
+
result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
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.12
|
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-05-
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,8 +95,11 @@ files:
|
|
95
95
|
- lib/daitai/functions/comparator.rb
|
96
96
|
- lib/daitai/functions/compose.rb
|
97
97
|
- lib/daitai/functions/concat.rb
|
98
|
+
- lib/daitai/functions/cond.rb
|
98
99
|
- lib/daitai/functions/dec.rb
|
99
100
|
- lib/daitai/functions/divide.rb
|
101
|
+
- lib/daitai/functions/equals.rb
|
102
|
+
- lib/daitai/functions/false.rb
|
100
103
|
- lib/daitai/functions/filter.rb
|
101
104
|
- lib/daitai/functions/flip.rb
|
102
105
|
- lib/daitai/functions/head.rb
|
@@ -130,6 +133,7 @@ files:
|
|
130
133
|
- lib/daitai/functions/sum.rb
|
131
134
|
- lib/daitai/functions/tail.rb
|
132
135
|
- lib/daitai/functions/tap.rb
|
136
|
+
- lib/daitai/functions/true.rb
|
133
137
|
- lib/daitai/functions/xor.rb
|
134
138
|
- lib/daitai/version.rb
|
135
139
|
homepage: https://github.com/walerian777/daitai
|