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

sequtils.take(a: iterable, max: int): seq #504

Open
timotheecour opened this issue Jan 2, 2021 · 0 comments
Open

sequtils.take(a: iterable, max: int): seq #504

timotheecour opened this issue Jan 2, 2021 · 0 comments

Comments

@timotheecour
Copy link
Owner

timotheecour commented Jan 2, 2021

add this to sequtils:

Example

when true:
  template take*(a: untyped, max: int): untyped =
    type T = typeof(block: (for ai in a: ai))
    var ret: seq[T]
    var i = 0
    if max > 0:
      for ai in a:
        ret.add ai
        i.inc
        if i >= max: break
    ret

note

we could also add takeExactly where we'd raise if we don't have enough elements

other languages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant