S
Simon Strandgaard
homepage:
http://raa.ruby-lang.org/list.rhtml?name=iterator
download:
http://rubyforge.org/download.php/213/iterator-0.1.tar.gz
About
=====
If Ryby's native iterators (yield+each) ain't flexible enough,
you may want to try using this collection of bidirectional
iterator classes. Building custom iterator classes are simple.
This is a simple implementation of GoF iterator-pattern.
Status
======
The overall design are stable. I don't expect any big changes.
Collection, iterates over an Array or similar containers.
Reverse, decorator which reverses the iterator.
Range, iterate in the range between two iterators.
Concat, concat multiple iterators into one.
Continuation, turn #each_word/#each_byte into an iterator.
License
=======
Ruby's license.
Example
=======
We can virtually concatene two arrays, so that they appear
as they were a single array.
def test_concat_sort
i1 = [5, 3, 1].create_iterator
i2 = [2, 4, 6].create_iterator
iterator = Iterator::Concat.new(i1, i2)
assert_equal((1..6).to_a, iterator.sort)
end
The iterator base class looks like this.
Please comment on this interface. Is it OK?
Does it need anything?
class Iterator
# close iterator after usage.
def close
# set position at first element
def first
# goto next element
def next
# true if we have reached the end
def is_done?
# set position at last element
def last
# goto previous element
def prev
# get the value of current element
def current
# set the value of current element
def current=(value)
# iterate over all elements (forward)
def each
# iterate over all elements (backward)
def reverse_each
# create a reverse iterator
def reverse
# typical enum methods also
include Enumerable
end
Authors last words
==================
We are curios to hear what your first-impression are, What do
you want from 'iterator.rb'? What are your requirements?
Please contribute with extensions or suggestions. In case you
observe bugs or other misbehavier, then please drop us a mail.
Messages must be submitted via this web-forum (prefered way of contact):
http://rubyforge.org/forum/forum.php?forum_id=46
http://raa.ruby-lang.org/list.rhtml?name=iterator
download:
http://rubyforge.org/download.php/213/iterator-0.1.tar.gz
About
=====
If Ryby's native iterators (yield+each) ain't flexible enough,
you may want to try using this collection of bidirectional
iterator classes. Building custom iterator classes are simple.
This is a simple implementation of GoF iterator-pattern.
Status
======
The overall design are stable. I don't expect any big changes.
Collection, iterates over an Array or similar containers.
Reverse, decorator which reverses the iterator.
Range, iterate in the range between two iterators.
Concat, concat multiple iterators into one.
Continuation, turn #each_word/#each_byte into an iterator.
License
=======
Ruby's license.
Example
=======
We can virtually concatene two arrays, so that they appear
as they were a single array.
def test_concat_sort
i1 = [5, 3, 1].create_iterator
i2 = [2, 4, 6].create_iterator
iterator = Iterator::Concat.new(i1, i2)
assert_equal((1..6).to_a, iterator.sort)
end
The iterator base class looks like this.
Please comment on this interface. Is it OK?
Does it need anything?
class Iterator
# close iterator after usage.
def close
# set position at first element
def first
# goto next element
def next
# true if we have reached the end
def is_done?
# set position at last element
def last
# goto previous element
def prev
# get the value of current element
def current
# set the value of current element
def current=(value)
# iterate over all elements (forward)
def each
# iterate over all elements (backward)
def reverse_each
# create a reverse iterator
def reverse
# typical enum methods also
include Enumerable
end
Authors last words
==================
We are curios to hear what your first-impression are, What do
you want from 'iterator.rb'? What are your requirements?
Please contribute with extensions or suggestions. In case you
observe bugs or other misbehavier, then please drop us a mail.
Messages must be submitted via this web-forum (prefered way of contact):
http://rubyforge.org/forum/forum.php?forum_id=46