goby-lang / goby

Goby - Yet another programming language written in Go
MIT License
3.49k stars 171 forks source link

Implement Enumerable Module with Enumerator Class #342

Open Alexius-Huang opened 7 years ago

Alexius-Huang commented 7 years ago

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.

Alexius-Huang commented 7 years ago

Hint: * means if no block given, then returns the Enumerator itself

Method list implementation:

st0012 commented 5 years ago

@Maxwell-Alexius Are you still interested in working on this?

Alexius-Huang commented 5 years ago

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

hachi8833 commented 5 years ago

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.

image

image

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.

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,

st0012 commented 5 years ago

@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

  1. creating the Enumerable module
  2. moving most of the Array's methods into Enumerable and make Array include it
  3. Implement Enumerator class

And from the screenshot, you uploaded your implementation looks cool! Can you open a PR for it?

hachi8833 commented 5 years ago

@st1102 thank you for the checking! I just wanted a grand design from you around Enumerable😊

I'd send the WIP PR

hachi8833 commented 5 years ago

@Maxwell-Alexius I hope you could check https://github.com/goby-lang/goby/pull/801