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
0e9c9acc
Commit
0e9c9acc
authored
Nov 30, 2016
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ksss-enumerator-lazy'
parents
3cf66a82
779c2629
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
10 deletions
+12
-10
mrbgems/default.gembox
mrbgems/default.gembox
+1
-1
mrbgems/mruby-enum-lazy/mrbgem.rake
mrbgems/mruby-enum-lazy/mrbgem.rake
+1
-1
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
+4
-2
mrbgems/mruby-enum-lazy/test/lazy.rb
mrbgems/mruby-enum-lazy/test/lazy.rb
+6
-6
No files found.
mrbgems/default.gembox
View file @
0e9c9acc
...
...
@@ -53,7 +53,7 @@ MRuby::GemBox.new do |conf|
# Use Enumerator class (require mruby-fiber)
conf.gem :core => "mruby-enumerator"
# Use Enumera
ble
::Lazy class (require mruby-enumerator)
# Use Enumera
tor
::Lazy class (require mruby-enumerator)
conf.gem :core => "mruby-enum-lazy"
# Use toplevel object (main) methods extension
...
...
mrbgems/mruby-enum-lazy/mrbgem.rake
View file @
0e9c9acc
MRuby
::
Gem
::
Specification
.
new
(
'mruby-enum-lazy'
)
do
|
spec
|
spec
.
license
=
'MIT'
spec
.
author
=
'mruby developers'
spec
.
summary
=
'Enumera
ble
::Lazy class'
spec
.
summary
=
'Enumera
tor
::Lazy class'
spec
.
add_dependency
(
'mruby-enumerator'
,
:core
=>
'mruby-enumerator'
)
spec
.
add_dependency
(
'mruby-enum-ext'
,
:core
=>
'mruby-enum-ext'
)
end
mrbgems/mruby-enum-lazy/mrblib/lazy.rb
View file @
0e9c9acc
...
...
@@ -2,7 +2,7 @@ module Enumerable
# = Enumerable#lazy implementation
#
# Enumerable#lazy returns an instance of Enumera
ble
::Lazy.
# Enumerable#lazy returns an instance of Enumera
tor
::Lazy.
# You can use it just like as normal Enumerable object,
# except these methods act as 'lazy':
#
...
...
@@ -16,9 +16,11 @@ module Enumerable
# - flat_map collect_concat
# - zip
def
lazy
Lazy
.
new
(
self
)
Enumerator
::
Lazy
.
new
(
self
)
end
end
class
Enumerator
# == Acknowledgements
#
# Based on https://github.com/yhara/enumerable-lazy
...
...
mrbgems/mruby-enum-lazy/test/lazy.rb
View file @
0e9c9acc
assert
(
"Enumera
ble
::Lazy"
)
do
assert
(
"Enumera
tor
::Lazy"
)
do
a
=
[
1
,
2
]
assert_equal
Enumera
ble
::
Lazy
,
a
.
lazy
.
class
assert_equal
Enumera
tor
::
Lazy
,
a
.
lazy
.
class
end
assert
(
"Enumera
ble
::Lazy laziness"
)
do
assert
(
"Enumera
tor
::Lazy laziness"
)
do
a
=
Object
.
new
def
a
.
each
return
to_enum
:each
unless
block_given?
...
...
@@ -40,13 +40,13 @@ assert("Enumerable::Lazy laziness") do
assert_equal
[
10
,
20
],
a
.
b
end
assert
(
"Enumra
ble
::Lazy#to_enum"
)
do
assert
(
"Enumra
tor
::Lazy#to_enum"
)
do
lazy_enum
=
(
0
..
Float
::
INFINITY
).
lazy
.
to_enum
(
:each_slice
,
2
)
assert_kind_of
Enumera
ble
::
Lazy
,
lazy_enum
assert_kind_of
Enumera
tor
::
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
(
"Enumera
ble
::Lazy#zip with cycle"
)
do
assert
(
"Enumera
tor
::Lazy#zip with cycle"
)
do
e1
=
[
1
,
2
,
3
].
cycle
e2
=
[
:a
,
:b
].
cycle
assert_equal
[[
1
,
:a
],[
2
,
:b
],[
3
,
:a
]],
e1
.
lazy
.
zip
(
e2
).
first
(
3
)
...
...
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