j8-functional 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +73 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +51 -0
- data/bin/console +55 -0
- data/bin/setup +8 -0
- data/j8-functional.gemspec +38 -0
- data/lib/j8-functional.rb +3 -0
- data/lib/j8/bi_consumer.rb +22 -0
- data/lib/j8/bi_function.rb +17 -0
- data/lib/j8/bi_predicate.rb +27 -0
- data/lib/j8/binary_operator.rb +17 -0
- data/lib/j8/collector.rb +6 -0
- data/lib/j8/collectors.rb +6 -0
- data/lib/j8/common.rb +60 -0
- data/lib/j8/comparator.rb +25 -0
- data/lib/j8/consumer.rb +22 -0
- data/lib/j8/function.rb +27 -0
- data/lib/j8/functional.rb +26 -0
- data/lib/j8/functional/exceptions.rb +7 -0
- data/lib/j8/functional/version.rb +7 -0
- data/lib/j8/optional.rb +105 -0
- data/lib/j8/predicate.rb +31 -0
- data/lib/j8/stream.rb +177 -0
- data/lib/j8/supplier.rb +11 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b9e2b0c42cb60af7daa1868853d3789fce763c7facc1f32babed4332f84c3006
|
4
|
+
data.tar.gz: 13a446ec85d5a3a76762eaae53523ace453cc4485ef6da899f03607263d61b0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 55410484125ad656e0c51b19a1429d92392925be037d7ef7c881fab92f5431024c67660ab106ded38f66ce105337f47e5d2d6c392f97753b5f87690680a92ee5
|
7
|
+
data.tar.gz: 2b2740b2aa100b765c1aa99c87c8a047a8fa0ebf8190a415a37c37364c6db6add34ffab9be03240f2e56db6f0dae179086a1636c4f4a5632fb94ebbc8fdcc3d9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.7
|
5
|
+
NewCops: enable
|
6
|
+
|
7
|
+
Naming/FileName:
|
8
|
+
Exclude:
|
9
|
+
- '**/j8-functional.rb'
|
10
|
+
|
11
|
+
Lint/EmptyClass:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Naming/MethodParameterName:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/Semicolon:
|
21
|
+
Exclude:
|
22
|
+
- '**/function_spec.rb'
|
23
|
+
|
24
|
+
Layout/LineLength:
|
25
|
+
Max: 120
|
26
|
+
|
27
|
+
Metrics/BlockLength:
|
28
|
+
Exclude:
|
29
|
+
- '*.gemspec'
|
30
|
+
- '**/*_spec.rb'
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
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 john@shields.wtf. 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 [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
j8-functional (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
ffi (1.13.1)
|
13
|
+
gem-release (2.2.0)
|
14
|
+
method_source (1.0.0)
|
15
|
+
parallel (1.20.1)
|
16
|
+
parser (2.7.2.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
pry (0.13.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
pry-doc (1.1.0)
|
22
|
+
pry (~> 0.11)
|
23
|
+
yard (~> 0.9.11)
|
24
|
+
rainbow (3.0.0)
|
25
|
+
rake (10.5.0)
|
26
|
+
rb-inotify (0.10.1)
|
27
|
+
ffi (~> 1.0)
|
28
|
+
regexp_parser (2.0.0)
|
29
|
+
rexml (3.2.4)
|
30
|
+
rspec (3.10.0)
|
31
|
+
rspec-core (~> 3.10.0)
|
32
|
+
rspec-expectations (~> 3.10.0)
|
33
|
+
rspec-mocks (~> 3.10.0)
|
34
|
+
rspec-core (3.10.0)
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-expectations (3.10.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.10.0)
|
39
|
+
rspec-mocks (3.10.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.10.0)
|
42
|
+
rspec-support (3.10.0)
|
43
|
+
rubocop (1.6.1)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 2.7.1.5)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8, < 3.0)
|
48
|
+
rexml
|
49
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
52
|
+
rubocop-ast (1.3.0)
|
53
|
+
parser (>= 2.7.1.5)
|
54
|
+
ruby-progressbar (1.10.1)
|
55
|
+
unicode-display_width (1.7.0)
|
56
|
+
yard (0.9.25)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bundler
|
63
|
+
gem-release
|
64
|
+
j8-functional!
|
65
|
+
pry
|
66
|
+
pry-doc
|
67
|
+
rake (~> 10.0)
|
68
|
+
rb-inotify
|
69
|
+
rspec (~> 3.0)
|
70
|
+
rubocop
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 John Shields
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
# J8::Streams
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/j8/streams`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'j8-functional'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install j8-functional
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Needs to be filled in. Demos
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
def demo(values)
|
29
|
+
values
|
30
|
+
&.j8_stream
|
31
|
+
&.map { |o| o + 5 }
|
32
|
+
&.filter { |o| o % 3 == 0 }
|
33
|
+
&.to_a
|
34
|
+
end
|
35
|
+
|
36
|
+
[18] pry(main)> demo([6,54,3,1,3,5,6,90,85])
|
37
|
+
=> [6, 90]
|
38
|
+
[19] pry(main)>
|
39
|
+
|
40
|
+
class Mod3Predicate < J8::Predicate
|
41
|
+
def initialize; end
|
42
|
+
|
43
|
+
def test(o)
|
44
|
+
o % 3 == 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def demo2(values)
|
49
|
+
values
|
50
|
+
&.j8_stream
|
51
|
+
&.map { |o| o + 5 }
|
52
|
+
&.filter(Mod3Predicate.new)
|
53
|
+
&.to_a
|
54
|
+
end
|
55
|
+
|
56
|
+
[19] pry(main)> demo2([6,54,3,1,3,5,6,90,85])
|
57
|
+
=> [6, 90]
|
58
|
+
[20] pry(main)>
|
59
|
+
|
60
|
+
class ModPredicate < J8::Predicate
|
61
|
+
def initialize(mod)
|
62
|
+
@mod = mod
|
63
|
+
end
|
64
|
+
|
65
|
+
def test(o)
|
66
|
+
o % @mod == 0
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def demo3(values)
|
71
|
+
values
|
72
|
+
&.j8_stream
|
73
|
+
&.map { |o| o + 5 }
|
74
|
+
&.filter(ModPredicate.new(3))
|
75
|
+
&.to_a
|
76
|
+
end
|
77
|
+
|
78
|
+
[20] pry(main)> demo3([6,54,3,1,3,5,6,90,85])
|
79
|
+
=> [6, 90]
|
80
|
+
[21] pry(main)>
|
81
|
+
|
82
|
+
class Add5Function < J8::Function
|
83
|
+
def initialize; end
|
84
|
+
|
85
|
+
def apply(o)
|
86
|
+
o + 5
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def demo4(values)
|
91
|
+
values
|
92
|
+
&.j8_stream
|
93
|
+
&.map(Add5Function.new)
|
94
|
+
&.filter(ModPredicate.new(3))
|
95
|
+
&.to_a
|
96
|
+
end
|
97
|
+
|
98
|
+
[21] pry(main)> demo4([6,54,3,1,3,5,6,90,85])
|
99
|
+
=> [6, 90]
|
100
|
+
[22] pry(main)>
|
101
|
+
|
102
|
+
class AddFunction < J8::Function
|
103
|
+
def initialize(amount)
|
104
|
+
@amount = amount
|
105
|
+
end
|
106
|
+
|
107
|
+
def apply(o)
|
108
|
+
o + @amount
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def demo5(values)
|
113
|
+
values
|
114
|
+
&.j8_stream
|
115
|
+
&.map(AddFunction.new(5))
|
116
|
+
&.filter(ModPredicate.new(3))
|
117
|
+
&.to_a
|
118
|
+
end
|
119
|
+
|
120
|
+
[22] pry(main)> demo5([6,54,3,1,3,5,6,90,85])
|
121
|
+
=> [6, 90]
|
122
|
+
[23] pry(main)>
|
123
|
+
```
|
124
|
+
|
125
|
+
## Development
|
126
|
+
|
127
|
+
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.
|
128
|
+
|
129
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
130
|
+
|
131
|
+
## Contributing
|
132
|
+
|
133
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/j8-functional. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/j8-functional/blob/master/CODE_OF_CONDUCT.md).
|
134
|
+
|
135
|
+
|
136
|
+
## License
|
137
|
+
|
138
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
139
|
+
|
140
|
+
## Code of Conduct
|
141
|
+
|
142
|
+
Everyone interacting in the J8::Streams project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/j8-functional/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
def empty_directory(directory)
|
8
|
+
FileUtils.remove_entry(directory)
|
9
|
+
FileUtils.mkdir(directory)
|
10
|
+
end
|
11
|
+
|
12
|
+
# clean up the workspace
|
13
|
+
task(:clean) do
|
14
|
+
empty_directory('doc')
|
15
|
+
empty_directory('out')
|
16
|
+
empty_directory('pkg')
|
17
|
+
end
|
18
|
+
|
19
|
+
# unit tests
|
20
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
21
|
+
task.pattern = 'spec/**/*_spec.rb'
|
22
|
+
task.rspec_opts = '--require spec_helper ' \
|
23
|
+
'--format documentation ' \
|
24
|
+
'--format html ' \
|
25
|
+
'--out out/rspec_unit.html'
|
26
|
+
end
|
27
|
+
task(default: :spec)
|
28
|
+
|
29
|
+
# configure rubocop
|
30
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
31
|
+
task.options = [
|
32
|
+
'--format', 'simple',
|
33
|
+
'--format', 'html',
|
34
|
+
'--out', 'out/rubocop.html',
|
35
|
+
'lib/**/*.rb',
|
36
|
+
'spec/**/*.rb'
|
37
|
+
]
|
38
|
+
end
|
39
|
+
task(default: :rubocop)
|
40
|
+
|
41
|
+
# Require tests, syntax and documentation to pass before building
|
42
|
+
task(build: %i[spec rubocop])
|
43
|
+
|
44
|
+
# Require a succesful build before release
|
45
|
+
task(release: %i[build])
|
46
|
+
|
47
|
+
task(:console) do
|
48
|
+
# protect ctrl-c in pry
|
49
|
+
trap(:SIGINT) {}
|
50
|
+
sh 'bundle exec bin/console'
|
51
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'j8/functional'
|
6
|
+
|
7
|
+
require 'pry'
|
8
|
+
require 'rb-inotify'
|
9
|
+
|
10
|
+
def reloadable_dirs
|
11
|
+
Dir[File.join(__dir__, '..', 'lib', '**', '*.rb')]
|
12
|
+
.map { |path| File.dirname(path) }
|
13
|
+
.push(File.join(__dir__, '..', 'lib'))
|
14
|
+
.to_set
|
15
|
+
.to_a
|
16
|
+
end
|
17
|
+
|
18
|
+
def reloadable_files
|
19
|
+
reloadable_dirs.map { |dir| Dir["#{dir}/**/*.rb"] }.flatten
|
20
|
+
end
|
21
|
+
|
22
|
+
def reload!
|
23
|
+
reloadable_files.each(&method(:load))
|
24
|
+
end
|
25
|
+
|
26
|
+
def reloadable_notifier(dirs) # rubocop:disable Metrics/MethodLength
|
27
|
+
INotify::Notifier.new.tap do |notifier|
|
28
|
+
dirs.each do |dir|
|
29
|
+
notifier.watch(dir, :modify, :recursive) do |event|
|
30
|
+
path = File.join(event.watcher.path, event.name)
|
31
|
+
next unless path.end_with?('.rb')
|
32
|
+
|
33
|
+
begin
|
34
|
+
load File.expand_path(path)
|
35
|
+
rescue => e # rubocop:disable Style/RescueStandardError
|
36
|
+
puts "Failed to load #{path}. #{e.class}: #{e.message}"
|
37
|
+
next
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end.run
|
42
|
+
end
|
43
|
+
|
44
|
+
def restart_reloader
|
45
|
+
return if @reloader_thread&.alive?
|
46
|
+
|
47
|
+
@reloader_thread&.join
|
48
|
+
@reloader_thread = Thread.new do
|
49
|
+
Thread.current.report_on_exception = false
|
50
|
+
reloadable_notifier(reloadable_dirs)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
restart_reloader
|
55
|
+
Pry.start
|