Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
3cf66a82
Commit
3cf66a82
authored
Nov 30, 2016
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Nov 30, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3305 from ksss/lazy-to_enum
Implement Enumerable::Lazy#to_enum and enum_for
parents
2bb47add
8675975b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
0 deletions
+15
-0
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
+9
-0
mrbgems/mruby-enum-lazy/test/lazy.rb
mrbgems/mruby-enum-lazy/test/lazy.rb
+6
-0
No files found.
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
View file @
3cf66a82
...
@@ -40,6 +40,15 @@ module Enumerable
...
@@ -40,6 +40,15 @@ module Enumerable
}
}
end
end
def
to_enum
(
meth
=
:each
,
*
args
,
&
block
)
lz
=
Lazy
.
new
(
self
,
&
block
)
lz
.
obj
=
self
lz
.
meth
=
meth
lz
.
args
=
args
lz
end
alias
enum_for
to_enum
def
map
(
&
block
)
def
map
(
&
block
)
Lazy
.
new
(
self
){
|
yielder
,
val
|
Lazy
.
new
(
self
){
|
yielder
,
val
|
yielder
<<
block
.
call
(
val
)
yielder
<<
block
.
call
(
val
)
...
...
mrbgems/mruby-enum-lazy/test/lazy.rb
View file @
3cf66a82
...
@@ -40,6 +40,12 @@ assert("Enumerable::Lazy laziness") do
...
@@ -40,6 +40,12 @@ assert("Enumerable::Lazy laziness") do
assert_equal
[
10
,
20
],
a
.
b
assert_equal
[
10
,
20
],
a
.
b
end
end
assert
(
"Enumrable::Lazy#to_enum"
)
do
lazy_enum
=
(
0
..
Float
::
INFINITY
).
lazy
.
to_enum
(
:each_slice
,
2
)
assert_kind_of
Enumerable
::
Lazy
,
lazy_enum
assert_equal
[
0
*
1
,
2
*
3
,
4
*
5
,
6
*
7
],
lazy_enum
.
map
{
|
a
|
a
.
first
*
a
.
last
}.
first
(
4
)
end
assert
(
"Enumerable::Lazy#zip with cycle"
)
do
assert
(
"Enumerable::Lazy#zip with cycle"
)
do
e1
=
[
1
,
2
,
3
].
cycle
e1
=
[
1
,
2
,
3
].
cycle
e2
=
[
:a
,
:b
].
cycle
e2
=
[
:a
,
:b
].
cycle
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment