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

Patch the standard library to make use of concepts like Iterable and Indexable #50

Open
Araq opened this issue Jun 8, 2018 · 4 comments

Comments

@Araq
Copy link
Member

Araq commented Jun 8, 2018

Once the most pressing concept bugs are fixed, the stdlib should make use of them. Especially the concepts Iterable and Indexable should be introduced and used in the standard library, in particular in the modules sequtils and algorithm for a start.

Suggestion:

type
  Iterable* = concept c
    for x in items(c): discard

  Indexable*[T] = concept c
    var i: int
    c[i] is T
    c.len is int
@awr1
Copy link

awr1 commented Aug 21, 2018

Should we add a concept for seq-ish stretchy buffer types as well? e.g. supports add(), setLen()? I recall years ago someone implementing their own alternative to seq in Nim - not really sure what the reason was. Such an addition is probably super unnecessary but just throwing that out there.

Deferring to @mratsim 's suggestion here I would suggest sequtils.map() should return the same type as its input (and presumably change the input type to one that satisfies Iterable). It might also be ideal to change the name of sequtils to something like containers or higherorder or functors.

@timotheecour
Copy link
Member

timotheecour commented Aug 27, 2018

IMO the best is instead for map + friends to return an iterator; that view is shared by @zah here

I do share the view that the best possible way to define map is as an iterator [see rest of comment]

that should be done in a different module to avoid confusion; RFC to come later.

@github-actions
Copy link

This RFC is stale because it has been open for 1095 days with no activity. Contribute a fix or comment on the issue, or it will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jun 15, 2023
@ZoomRmc
Copy link

ZoomRmc commented Jun 15, 2023

Since now we have a iterable[t] that's a magic type, it would be nice to have some comparison between the two options and plans for defining the proper way of handling iterators.

@github-actions github-actions bot removed the Stale label Jun 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants