Open Alexius-Huang opened 7 years ago
Hint: * means if no block given, then returns the Enumerator itself
Method list implementation:
Enumerable#all?
Returns true
if the block never returns false
or nil
Enumerable#any?
Returns true
if the block ever returns a value other than false
or nil
*Enumerable#chunk
Enumerates over items and chunking them together based on the return value of blockEnumerable#chunk_while
Creates a enumerator for each chunked elements *Enumerable#map
and *Enumerable#collect
*Enumerable#flat_map
and *Enumerable#collect_concat
Enumerable#count
true
value*Enumerable#cycle
Default runs forever, if specified number n
then runs enumerator n
times repeated*Enumerable#detect
Enumerator#find
Enumerable#drop
Drops first n
elements from enumerator and return rest elements in an array*Enumerable#drop_while
Drops elements up to, but not including, the first element for which the block returns nil
or false
and returns an array containing the remaining elements*Enumerable#each_cons
and Enumerable#each_slice
Iterates the given block for each array of consecutive n
elements*Enumerable#each_entry
Converting multiple values from yield to an array*Enumerable#each_with_index
*Enumerable#each_with_object
Enumerable#entries
and Enumerable#to_a
Returns array containing items in enumeratorEnumerable#empty?
Returns true
if no elements*Enumerable#find_all
and *Enumerable#select
*Enumerable#find_index
false
Enumerable#first
Returns first n
element (default n
is 1)Enumerable#grep
Enumerable#grep_v
Inverted version of #grep
*Enumerable#group_by
Groups collection by the result of the block which returns a hashEnumerable#include?
and Enumerable#member?
Enumerable#inject
and Enumerable#reduce
Enumerable#lazy
(Lazy Enumerator need more survey)Enumerable#max
Returns the object of enum with n
maximun value (default n
is 1)*Enumerable#max_by
Enumerable#min
Inversed version of #max
*Enumerable#min_by
Inversed version of #max_by
Enumerable#minmax
(???)*Enumerable#minmax_by
(???)Enumerable#none?
Returns true
if none of the block value results true
([nil]
is none but not empty!)Enumerable#one?
Returns true
if block result returns true
exactly onceEnumerable#partition
Returns two array elements in an array which the first array stores the value that the block evaluates true
while the second array stores value that the block evaluates false
*Enumerable#reject
Returns array of all elements for which block result false
*Enumerable#reverse_each
Enumerable#slice_after
Enumerable#slice_before
Enumerable#slice_when
Enumerable#sort
*Enumerable#sort_by
Enumerable#take
Returns first n
elements (different from #first
, #take
needs to specifiy argument as an integer)*Enumerable#take_while
Enumerable#to_a
Enumerable#to_h
Enumerable#unique
Returns a new array by removing duplicated value in self
Enumerable#zip
@Maxwell-Alexius Are you still interested in working on this?
I'm not sure I can handle this ton of works and I haven't been using Ruby for a long time since working on JS related things, it might take me time to pick up and inspect the Enumerable
mechanism in Ruby again.
I would prefer others can pick up this issue and build the main Enumerator class.
If the main class is built, I think I can assist in implementing the Enumerable#method
part
Seeing Maxwell's recent comment, I've been surveying around Enumerator in Ruby and Goby, and I built a very primitive Enumerator class as a mock on my local rep that can be compiled so far. I think it is possible to build.
But now I'm wondering how to proceed farther. In other words, I think we need a grand design around organizing Enumerator and Enumerable (and perhaps Lazy and Block) classes in Goby.
each
is good for consistency, but I also guess that Enumerator class might be just for instantiating Enumerator as Block class does like that.This is just a draft memorandum and is not final. If needed, I create a new issue for that. I'd be glad if @st0012 would show ideas around this.
Thank you,
@hachi8833 sorry for the late response
I don't use either Enumerator
or Enumerable
directly very often, so I have limited understanding about those 2. I think we can start by
Enumerable
moduleEnumerable
and make Array include itEnumerator
classAnd from the screenshot, you uploaded your implementation looks cool! Can you open a PR for it?
@st1102 thank you for the checking! I just wanted a grand design from you around Enumerable😊
I'd send the WIP PR
@Maxwell-Alexius I hope you could check https://github.com/goby-lang/goby/pull/801
Enumerable
module in Ruby originally was included in Array class and it has pre-defined methods such as the#map
,#select
and#reduce
. In original Ruby, it requires also to define the#each
method when included Enumerable module.