daitai 0.1.9 → 0.1.10

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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +38 -0
  4. data/lib/daitai.rb +5 -1
  5. data/lib/daitai/{abs.rb → functions/abs.rb} +0 -0
  6. data/lib/daitai/{add.rb → functions/add.rb} +0 -0
  7. data/lib/daitai/{all.rb → functions/all.rb} +0 -0
  8. data/lib/daitai/{always.rb → functions/always.rb} +0 -0
  9. data/lib/daitai/{and.rb → functions/and.rb} +0 -0
  10. data/lib/daitai/{any.rb → functions/any.rb} +0 -0
  11. data/lib/daitai/functions/comparator.rb +19 -0
  12. data/lib/daitai/{compose.rb → functions/compose.rb} +0 -0
  13. data/lib/daitai/{concat.rb → functions/concat.rb} +0 -0
  14. data/lib/daitai/{dec.rb → functions/dec.rb} +0 -0
  15. data/lib/daitai/{divide.rb → functions/divide.rb} +0 -0
  16. data/lib/daitai/{filter.rb → functions/filter.rb} +0 -0
  17. data/lib/daitai/{flip.rb → functions/flip.rb} +0 -0
  18. data/lib/daitai/{head.rb → functions/head.rb} +0 -0
  19. data/lib/daitai/{identity.rb → functions/identity.rb} +0 -0
  20. data/lib/daitai/{inc.rb → functions/inc.rb} +0 -0
  21. data/lib/daitai/{init.rb → functions/init.rb} +0 -0
  22. data/lib/daitai/{is.rb → functions/is.rb} +0 -0
  23. data/lib/daitai/{is_nil.rb → functions/is_nil.rb} +0 -0
  24. data/lib/daitai/{last.rb → functions/last.rb} +0 -0
  25. data/lib/daitai/{length.rb → functions/length.rb} +0 -0
  26. data/lib/daitai/{map.rb → functions/map.rb} +0 -0
  27. data/lib/daitai/{max.rb → functions/max.rb} +0 -0
  28. data/lib/daitai/{mean.rb → functions/mean.rb} +0 -0
  29. data/lib/daitai/{median.rb → functions/median.rb} +0 -0
  30. data/lib/daitai/{min.rb → functions/min.rb} +0 -0
  31. data/lib/daitai/{modulo.rb → functions/modulo.rb} +0 -0
  32. data/lib/daitai/{multiply.rb → functions/multiply.rb} +0 -0
  33. data/lib/daitai/{negate.rb → functions/negate.rb} +0 -0
  34. data/lib/daitai/{not.rb → functions/not.rb} +0 -0
  35. data/lib/daitai/functions/once.rb +19 -0
  36. data/lib/daitai/{or.rb → functions/or.rb} +0 -0
  37. data/lib/daitai/{pipe.rb → functions/pipe.rb} +0 -0
  38. data/lib/daitai/{product.rb → functions/product.rb} +0 -0
  39. data/lib/daitai/{reduce.rb → functions/reduce.rb} +0 -0
  40. data/lib/daitai/{reverse.rb → functions/reverse.rb} +0 -0
  41. data/lib/daitai/{signum.rb → functions/signum.rb} +0 -0
  42. data/lib/daitai/{sort.rb → functions/sort.rb} +0 -0
  43. data/lib/daitai/{sort_by.rb → functions/sort_by.rb} +0 -0
  44. data/lib/daitai/{sort_with.rb → functions/sort_with.rb} +0 -0
  45. data/lib/daitai/{subtract.rb → functions/subtract.rb} +0 -0
  46. data/lib/daitai/{sum.rb → functions/sum.rb} +0 -0
  47. data/lib/daitai/{tail.rb → functions/tail.rb} +0 -0
  48. data/lib/daitai/{xor.rb → functions/xor.rb} +0 -0
  49. data/lib/daitai/version.rb +1 -1
  50. metadata +46 -45
  51. data/CODE_OF_CONDUCT.md +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fd69882351f60ace283f0a3b53b28c651b8c086d567dae81e48554960e57079
4
- data.tar.gz: 976b181231035ae58bb8ce47eaf20df7b4e9f3397646a679f5804e1e58b2d119
3
+ metadata.gz: f33c401eb1bb4b6c132adc6c8fc3acb9188fba02be3e822ff3a84bd8016a90d1
4
+ data.tar.gz: 4a21a8e1af7469f2b99e948256030bc237d225f90fefa1f05f25adaab8b275e5
5
5
  SHA512:
6
- metadata.gz: bea4f7410e064302f083afa6971c649d3fa5d8b3c941f18eb5cfc2b1d70ac0394fd9b8f37b2f604dddf628da2e965805942f26dcb8ecb323551b92746309cd97
7
- data.tar.gz: 6512fac39887a98f87ccb95dccd1ba2d12c1799c53075e39870868a78a5b4f8dc2318ac8b776e2d50ffaca5439175f7d84f59adec38ff17d356f0f5de4c1eb0c
6
+ metadata.gz: 7cb001dfb253631cd5827bcb8d4dc59e67c2eb1a506e3a37dd7ec9eb9f73ed092ab08289867782571ea518a1b4aaba1c15f9e9fb8e7cfbe7009e2630c33450d4
7
+ data.tar.gz: e8a37f4cd00c87f713d094dcc571cc1bc51ef3ad72a81d04f7c619cf1cc9caf22fd2ed53de71fbd055db67ad7705b3887faabc35fd821aaa93f0bf2fadcd883b
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- daitai (0.1.9)
4
+ daitai (0.1.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -37,6 +37,7 @@ $ gem install daitai
37
37
  * [always](#always-definition)
38
38
  * [and](#and-definition)
39
39
  * [any](#any-definition)
40
+ * [comparator](#comparator-definition)
40
41
  * [compose](#compose-definition)
41
42
  * [concat](#concat-definition)
42
43
  * [dec](#dec-definition)
@@ -60,6 +61,7 @@ $ gem install daitai
60
61
  * [multiply](#multiply-definition)
61
62
  * [negate](#negate-definition)
62
63
  * [not](#not-definition)
64
+ * [once](#once-definition)
63
65
  * [or](#or-definition)
64
66
  * [pipe](#pipe-definition)
65
67
  * [product](#product-definition)
@@ -159,6 +161,25 @@ Daitai.any.(even, [1, 3, 5, 7]) # => false
159
161
 
160
162
  - - -
161
163
 
164
+ <h4 id='comparator-definition'>
165
+ <code>comparator :: (a -> b -> Boolean) -> (a -> b -> Numeric)</code>
166
+ </h4>
167
+
168
+ Creates a comparator function based on a function which checks if the first argument is greater than the second one.
169
+
170
+ ```ruby
171
+ apple = { colour: 'red', weight: 136 }
172
+ banana = { colour: 'yellow', weight: 118 }
173
+ pear = { colour: 'green', weight: 178 }
174
+
175
+ weight_comparator = Daitai.comparator.(->(a, b) { a[:weight] > b[:weight]})
176
+ by_weight_decreasingly = Daitai.sort_with.(weight_comparator)
177
+
178
+ by_weight_decreasingly.([apple, banana, pear]) # => [pear, apple, banana]
179
+ ```
180
+
181
+ - - -
182
+
162
183
  <h4 id='compose-definition'>
163
184
  <code>compose :: (b -> c) -> (a -> b) -> (a -> c)</code>
164
185
  </h4>
@@ -482,6 +503,23 @@ Daitai.not.(nil) # => true
482
503
 
483
504
  - - -
484
505
 
506
+ <h4 id='once-definition'>
507
+ <code>once :: (a -> … -> b) -> (a -> … -> b)</code>
508
+ </h4>
509
+
510
+ Returns a wrapped function which can be executed only once - no matter how many times it is called.
511
+
512
+ ```ruby
513
+ decrement = ->(x) { x - 1 }
514
+ decrement_once = Daitai.once.(decrement)
515
+
516
+ decrement_once.(8) # => 7
517
+ decrement_once.(40) # => 7
518
+ decrement_once.(decrement_once.(40)) # => 7
519
+ ```
520
+
521
+ - - -
522
+
485
523
  <h4 id='or-definition'>
486
524
  <code>or :: Bool -> Bool -> Bool</code>
487
525
  </h4>
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Dir["#{__dir__}/daitai/*"].each { |file| require file }
3
+ require 'daitai/version'
4
+
5
+ Dir["#{__dir__}/daitai/functions/*"].each { |file| require file }
4
6
 
5
7
  module Daitai
6
8
  extend Abs
@@ -9,6 +11,7 @@ module Daitai
9
11
  extend Always
10
12
  extend And
11
13
  extend Any
14
+ extend Comparator
12
15
  extend Compose
13
16
  extend Concat
14
17
  extend Dec
@@ -32,6 +35,7 @@ module Daitai
32
35
  extend Multiply
33
36
  extend Negate
34
37
  extend Not
38
+ extend Once
35
39
  extend Or
36
40
  extend Pipe
37
41
  extend Product
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Comparator
5
+ def comparator
6
+ lambda do |predicate|
7
+ ->(a, b) { evaluate(predicate, a, b) }
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def evaluate(predicate, a, b)
14
+ return -1 if predicate.(a, b)
15
+ return 1 if predicate.(b, a)
16
+ 0
17
+ end
18
+ end
19
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daitai
4
+ module Once
5
+ def once
6
+ lambda do |function|
7
+ called = false
8
+ result = nil
9
+
10
+ lambda do |*args|
11
+ return result if called
12
+
13
+ called = true
14
+ result = function.(*args)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daitai
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
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.9
4
+ version: 0.1.10
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-04-01 00:00:00.000000000 Z
11
+ date: 2018-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,7 +77,6 @@ files:
77
77
  - ".rspec"
78
78
  - ".rubocop.yml"
79
79
  - ".travis.yml"
80
- - CODE_OF_CONDUCT.md
81
80
  - Gemfile
82
81
  - Gemfile.lock
83
82
  - LICENSE.txt
@@ -87,49 +86,51 @@ files:
87
86
  - bin/setup
88
87
  - daitai.gemspec
89
88
  - lib/daitai.rb
90
- - lib/daitai/abs.rb
91
- - lib/daitai/add.rb
92
- - lib/daitai/all.rb
93
- - lib/daitai/always.rb
94
- - lib/daitai/and.rb
95
- - lib/daitai/any.rb
96
- - lib/daitai/compose.rb
97
- - lib/daitai/concat.rb
98
- - lib/daitai/dec.rb
99
- - lib/daitai/divide.rb
100
- - lib/daitai/filter.rb
101
- - lib/daitai/flip.rb
102
- - lib/daitai/head.rb
103
- - lib/daitai/identity.rb
104
- - lib/daitai/inc.rb
105
- - lib/daitai/init.rb
106
- - lib/daitai/is.rb
107
- - lib/daitai/is_nil.rb
108
- - lib/daitai/last.rb
109
- - lib/daitai/length.rb
110
- - lib/daitai/map.rb
111
- - lib/daitai/max.rb
112
- - lib/daitai/mean.rb
113
- - lib/daitai/median.rb
114
- - lib/daitai/min.rb
115
- - lib/daitai/modulo.rb
116
- - lib/daitai/multiply.rb
117
- - lib/daitai/negate.rb
118
- - lib/daitai/not.rb
119
- - lib/daitai/or.rb
120
- - lib/daitai/pipe.rb
121
- - lib/daitai/product.rb
122
- - lib/daitai/reduce.rb
123
- - lib/daitai/reverse.rb
124
- - lib/daitai/signum.rb
125
- - lib/daitai/sort.rb
126
- - lib/daitai/sort_by.rb
127
- - lib/daitai/sort_with.rb
128
- - lib/daitai/subtract.rb
129
- - lib/daitai/sum.rb
130
- - lib/daitai/tail.rb
89
+ - lib/daitai/functions/abs.rb
90
+ - lib/daitai/functions/add.rb
91
+ - lib/daitai/functions/all.rb
92
+ - lib/daitai/functions/always.rb
93
+ - lib/daitai/functions/and.rb
94
+ - lib/daitai/functions/any.rb
95
+ - lib/daitai/functions/comparator.rb
96
+ - lib/daitai/functions/compose.rb
97
+ - lib/daitai/functions/concat.rb
98
+ - lib/daitai/functions/dec.rb
99
+ - lib/daitai/functions/divide.rb
100
+ - lib/daitai/functions/filter.rb
101
+ - lib/daitai/functions/flip.rb
102
+ - lib/daitai/functions/head.rb
103
+ - lib/daitai/functions/identity.rb
104
+ - lib/daitai/functions/inc.rb
105
+ - lib/daitai/functions/init.rb
106
+ - lib/daitai/functions/is.rb
107
+ - lib/daitai/functions/is_nil.rb
108
+ - lib/daitai/functions/last.rb
109
+ - lib/daitai/functions/length.rb
110
+ - lib/daitai/functions/map.rb
111
+ - lib/daitai/functions/max.rb
112
+ - lib/daitai/functions/mean.rb
113
+ - lib/daitai/functions/median.rb
114
+ - lib/daitai/functions/min.rb
115
+ - lib/daitai/functions/modulo.rb
116
+ - lib/daitai/functions/multiply.rb
117
+ - lib/daitai/functions/negate.rb
118
+ - lib/daitai/functions/not.rb
119
+ - lib/daitai/functions/once.rb
120
+ - lib/daitai/functions/or.rb
121
+ - lib/daitai/functions/pipe.rb
122
+ - lib/daitai/functions/product.rb
123
+ - lib/daitai/functions/reduce.rb
124
+ - lib/daitai/functions/reverse.rb
125
+ - lib/daitai/functions/signum.rb
126
+ - lib/daitai/functions/sort.rb
127
+ - lib/daitai/functions/sort_by.rb
128
+ - lib/daitai/functions/sort_with.rb
129
+ - lib/daitai/functions/subtract.rb
130
+ - lib/daitai/functions/sum.rb
131
+ - lib/daitai/functions/tail.rb
132
+ - lib/daitai/functions/xor.rb
131
133
  - lib/daitai/version.rb
132
- - lib/daitai/xor.rb
133
134
  homepage: https://github.com/walerian777/daitai
134
135
  licenses:
135
136
  - MIT
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at walerian.sobczak@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/