daitai 0.1.7 → 0.1.8
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/Gemfile.lock +1 -1
- data/README.md +61 -0
- data/lib/daitai.rb +4 -0
- data/lib/daitai/always.rb +11 -0
- data/lib/daitai/concat.rb +3 -1
- data/lib/daitai/flip.rb +17 -0
- data/lib/daitai/identity.rb +9 -0
- data/lib/daitai/min.rb +3 -1
- data/lib/daitai/version.rb +1 -1
- data/lib/daitai/xor.rb +11 -0
- 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: 7b46501fd7f8f5f8728ce390c10bee1e01e270dd23d9138b4c789f3ef73ea91d
|
4
|
+
data.tar.gz: 0ef430632006a7529f577299882c0e8069d73e514015a8c94e043e58b478e163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31bc34d12c4d4ea1af384e1398d18437b063a864319a737f6f036b15cefdaa6e3a3224b02ff4e446a68cf9338bd4d94db1be8c64ba265baaf95f3aa6a54e1beb
|
7
|
+
data.tar.gz: c0dab7b6b0700d677e9e9e25e504b066dc22912ae8c8589c37216da969153d2e0a939e0db2474e2a282af30a6d2eac39d2d00074fdc60837b3544e12f221f136
|
data/Gemfile.lock
CHANGED
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.
|
data/lib/daitai.rb
CHANGED
@@ -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
|
data/lib/daitai/concat.rb
CHANGED
data/lib/daitai/flip.rb
ADDED
@@ -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
|
data/lib/daitai/min.rb
CHANGED
data/lib/daitai/version.rb
CHANGED
data/lib/daitai/xor.rb
ADDED
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.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-
|
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
|