enumerator-auto_forced_lazy 0.1.0
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 +7 -0
- data/LICENSE +20 -0
- data/README.md +20 -0
- data/enumerator-auto_forced_lazy.gemspec +30 -0
- data/lib/enumerable.rb +10 -0
- data/lib/enumerator-auto_forced_lazy.rb +2 -0
- data/lib/enumerator.rb +61 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c3704643ea64116858cc2e47992b7a3f1f4b0a16217f03a35ce19f441435d5ad
|
4
|
+
data.tar.gz: b968ca193cc565813bdf7ee38cc94389617bd5d4cb153bc5a9fe985867891df8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fc4b1c3971e1aa262870cafa823e6e139a4eccb1aa3fc826f587e2ce6c325ca5abb7423f6db2e495a47d2a3ebe0df2123a25a68ea55272b0ddf188c5c5d07124
|
7
|
+
data.tar.gz: 6378d0806fdc0413e9dac3a15a9bef0a9a6c10af2032c19eab126224cdb770936187e2221abce6a4fa520b84b4ba2a735739a9246d4bf1f9cb4b546a34511482
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2020 Gonçalo Cabrita
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
[gem]: https://rubygems.org/gems/enumerator-auto_forced_lazy
|
2
|
+
[actions]: https://github.com/gmcabrita/enumerator-auto_forced_lazy/actions
|
3
|
+
[inchpages]: http://inch-ci.org/github/gmcabrita/enumerator-auto_forced_lazy
|
4
|
+
[rubydoc]: https://rubydoc.info/gems/enumerator-auto_forced_lazy
|
5
|
+
|
6
|
+
# enumerator-auto_forced_lazy
|
7
|
+
|
8
|
+
[](actions)
|
9
|
+
[](gem)
|
10
|
+
[][inchpages]
|
11
|
+
|
12
|
+
## Links
|
13
|
+
|
14
|
+
- [API Documentation](rubydoc)
|
15
|
+
|
16
|
+
## Supported Ruby versions
|
17
|
+
|
18
|
+
This library officially supports the following Ruby versions:
|
19
|
+
|
20
|
+
- MRI >= `2.4`
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$:.push File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "enumerator-auto_forced_lazy"
|
7
|
+
spec.version = "0.1.0"
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.authors = ["Gonçalo Cabrita"]
|
10
|
+
spec.email = "_@gmcabrita.com"
|
11
|
+
spec.licenses = ["MIT"]
|
12
|
+
spec.summary = "Provides an AutoForcedLazy class that automatically forces the computation of an Enumerator::Lazy when needed."
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "https://github.com/gmcabrita/enumerator-auto_forced_lazy"
|
15
|
+
spec.metadata = {"source_code_uri" => "https://github.com/gmcabrita/enumerator-auto_forced_lazy"}
|
16
|
+
|
17
|
+
spec.files = Dir["LICENSE", "README.md", "enumerator-auto_forced_lazy.gemspec", "lib/**/*"]
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
spec.metadata["source_code_uri"] = "https://github.com/gmcabrita/enumerator-auto_forced_lazy"
|
22
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/gmcabrita/enumerator-auto_forced_lazy/issues"
|
23
|
+
|
24
|
+
spec.required_ruby_version = ">= 2.4.0"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
spec.add_development_dependency "standardrb"
|
30
|
+
end
|
data/lib/enumerable.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
# Returns an Enumerator::AutoForcedLazy, which wraps Enumerator::Lazy to
|
5
|
+
# provide access to Array methods without requiring a previous explicit call
|
6
|
+
# to Enumerator::Lazy#force.
|
7
|
+
def auto_forced_lazy
|
8
|
+
lazy.auto_force
|
9
|
+
end
|
10
|
+
end
|
data/lib/enumerator.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
4
|
+
|
5
|
+
class Enumerator
|
6
|
+
# Enumerator::AutoForcedLazy is a thin wrapper around Enumerator::Lazy that
|
7
|
+
# automatically calls Enumerator::Lazy#force before a method call if the
|
8
|
+
# called method does not exist on Enumerator::Lazy but exists on Array.
|
9
|
+
#
|
10
|
+
# Enumerator::AutoForcedLazy can be constructed from any Enumerator::Lazy
|
11
|
+
# with the Enumerator::Lazy#auto_force method.
|
12
|
+
#
|
13
|
+
# (1..Float::INFINITY).lazy.auto_force.take_while { |i| i < 30 }
|
14
|
+
# => #<Enumerator::Lazy: #<Enumerator::Lazy: 1..Infinity>:take_while>
|
15
|
+
#
|
16
|
+
# Alternatively, Enumerator::AutoForcedLazy can also be constructed from any
|
17
|
+
# and from any Enumerable with the Enumerable#auto_forced_lazy method.
|
18
|
+
#
|
19
|
+
# (1..Float::INFINITY).auto_forced_lazy.take_while { |i| i < 30 }
|
20
|
+
# => #<Enumerator::Lazy: #<Enumerator::Lazy: 1..Infinity>:take_while>
|
21
|
+
#
|
22
|
+
# It is useful for keeping lazy enumerator semantics while providing easier
|
23
|
+
# access to Array methods by not requiring users to explicitly call
|
24
|
+
# Enumerator::Lazy#force.
|
25
|
+
class AutoForcedLazy < SimpleDelegator
|
26
|
+
ARRAY_OBJ = [].freeze
|
27
|
+
|
28
|
+
def initialize(lazy_enum)
|
29
|
+
super(lazy_enum)
|
30
|
+
end
|
31
|
+
|
32
|
+
# rubocop:disable Style/MissingRespondToMissing
|
33
|
+
def method_missing(m, *args, &block)
|
34
|
+
if __getobj__.respond_to?(m)
|
35
|
+
result = __getobj__.send(m, *args, &block)
|
36
|
+
|
37
|
+
if result.is_a?(Enumerator::Lazy)
|
38
|
+
__setobj__(result)
|
39
|
+
|
40
|
+
self
|
41
|
+
else
|
42
|
+
result
|
43
|
+
end
|
44
|
+
elsif ARRAY_OBJ.respond_to?(m)
|
45
|
+
__getobj__.force.send(m, *args, &block)
|
46
|
+
else
|
47
|
+
super
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# rubocop:enable Style/MissingRespondToMissing
|
51
|
+
end
|
52
|
+
|
53
|
+
class Lazy
|
54
|
+
# Returns an Enumerator::AutoForcedLazy, which wraps Enumerator::Lazy to
|
55
|
+
# provide access to Array methods without requiring a previous explicit
|
56
|
+
# call to Enumerator::Lazy#force.
|
57
|
+
def auto_force
|
58
|
+
AutoForcedLazy.new(self)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enumerator-auto_forced_lazy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gonçalo Cabrita
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: standardrb
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Provides an AutoForcedLazy class that automatically forces the computation
|
70
|
+
of an Enumerator::Lazy when needed.
|
71
|
+
email: _@gmcabrita.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- enumerator-auto_forced_lazy.gemspec
|
79
|
+
- lib/enumerable.rb
|
80
|
+
- lib/enumerator-auto_forced_lazy.rb
|
81
|
+
- lib/enumerator.rb
|
82
|
+
homepage: https://github.com/gmcabrita/enumerator-auto_forced_lazy
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
source_code_uri: https://github.com/gmcabrita/enumerator-auto_forced_lazy
|
87
|
+
allowed_push_host: https://rubygems.org
|
88
|
+
bug_tracker_uri: https://github.com/gmcabrita/enumerator-auto_forced_lazy/issues
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.4.0
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.1.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Provides an AutoForcedLazy class that automatically forces the computation
|
108
|
+
of an Enumerator::Lazy when needed.
|
109
|
+
test_files: []
|