Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic Request: Iterator #90

Open
y9vad9 opened this issue Nov 23, 2022 · 0 comments
Open

Topic Request: Iterator #90

y9vad9 opened this issue Nov 23, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request topic related to topic

Comments

@y9vad9
Copy link
Owner

y9vad9 commented Nov 23, 2022

Is your topic request related to a problem? Please describe.
There is already some information about iterator in cycles and strings topics. Arrays (that ofc related to iterators) is very important structure to explain.

Describe the solution you'd like
I'd like to tell more about iterator (how it works in order to OOP in Kotlin). And make kinda example:

class Element(var string: String, var next: Element?)

class Elements(private var initial: Element) : Iterable<Element> {
   private var first: Element = initial
   
   fun iterator(): Iterator {
       return object : Iterator {
           private var current: Element = first

           override fun hasNext(): Boolean {
              return current.next != null
           }

         override fun next(): Element {
             val output = current
             current = current.next ?: throw IllegalStateException()
             return output
         }
       }
   }
}

Also example with own range realization.

What place topic should have? Why?
It should be after nullable and throwables topics.

@y9vad9 y9vad9 added enhancement New feature or request topic related to topic labels Nov 23, 2022
@y9vad9 y9vad9 self-assigned this Nov 23, 2022
@y9vad9 y9vad9 added this to the 1.0.0 milestone Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request topic related to topic
Projects
Status: No status
Development

No branches or pull requests

1 participant