{"action":"created","issue":{"url":"https://api.github.com/repos/chaniks/crystal/issues/4","repository_url":"https://api.github.com/repos/chaniks/crystal","labels_url":"https://api.github.com/repos/chaniks/crystal/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/chaniks/crystal/issues/4/comments","events_url":"https://api.github.com/repos/chaniks/crystal/issues/4/events","html_url":"https://github.com/chaniks/crystal/issues/4","id":181588193,"number":4,"title":"non-copying iteration","user":{"login":"chaniks","id":442239,"avatar_url":"https://avatars.githubusercontent.com/u/442239?v=3","gravatar_id":"","url":"https://api.github.com/users/chaniks","html_url":"https://github.com/chaniks","followers_url":"https://api.github.com/users/chaniks/followers","following_url":"https://api.github.com/users/chaniks/following{/other_user}","gists_url":"https://api.github.com/users/chaniks/gists{/gist_id}","starred_url":"https://api.github.com/users/chaniks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaniks/subscriptions","organizations_url":"https://api.github.com/users/chaniks/orgs","repos_url":"https://api.github.com/users/chaniks/repos","events_url":"https://api.github.com/users/chaniks/events{/privacy}","received_events_url":"https://api.github.com/users/chaniks/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-07T05:29:23Z","updated_at":"2016-10-07T10:42:27Z","closed_at":null,"body":"```crystal\r\nclass Indexable::ItemIterator\r\n  def limit(from : Int , count : Int, &block)\r\n    skip(from).first(count).each { |v| yield v } \r\n  end \r\n\r\n  def limit(range : Range, &block)\r\n      take = range.end\r\n      take += 1 unless range.excludes_end?\r\n      first(take).skip(range.begin).each { |v| yield v } \r\n  end \r\nend\r\n\r\narray = [\"a\", \"b\", \"c\", \"d\", \"e\"]\r\n\r\narray[1,3].each { |x| print x, \" -- \" }\r\nputs\r\n\r\narray.each.limit(1,3) { |x| print x, \" -- \" } \r\nputs\r\n\r\narray.each.limit(1..3) { |x| print x, \" -- \" }\r\nputs\r\n```\r\n\r\nPopped up in my mind while reading crystal-lang's **#**3386\r\n\r\n`each` for me means everything.  So I split them up.\r\n\r\nThough, I never liked the way `something[1,3]` where 3 implies the count, I'd better remove `limit(1,3)` but implement limit(n &block) instead:\r\n\r\n```crystal\r\narray.each.skip(1).limit(3) { ... }\r\n```\r\n\r\nThe naming is also a concern.\r\n\r\n```crystal\r\narray.each.limit(1..3) { ... }\r\narray.each.for(1..3) { ... }\r\narray.each.within(1..3) { ... }\r\narray.each.only(1..3) { ... }\r\narray.each.run(1..3) { ... }\r\n\r\narray.each.skip(1).run(3) { ... }\r\narray.each.run(3, offset: 1)  { ... }\r\narray.each.from(1).run(3) { ... } # (rename) skip -> from\r\narray.each.from(1).limit(3) { ... }\r\narray.each.run(3, from: 1) { ... }\r\n```"},"comment":{"url":"https://api.github.com/repos/chaniks/crystal/issues/comments/252212504","html_url":"https://github.com/chaniks/crystal/issues/4#issuecomment-252212504","issue_url":"https://api.github.com/repos/chaniks/crystal/issues/4","id":252212504,"user":{"login":"chaniks","id":442239,"avatar_url":"https://avatars.githubusercontent.com/u/442239?v=3","gravatar_id":"","url":"https://api.github.com/users/chaniks","html_url":"https://github.com/chaniks","followers_url":"https://api.github.com/users/chaniks/followers","following_url":"https://api.github.com/users/chaniks/following{/other_user}","gists_url":"https://api.github.com/users/chaniks/gists{/gist_id}","starred_url":"https://api.github.com/users/chaniks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaniks/subscriptions","organizations_url":"https://api.github.com/users/chaniks/orgs","repos_url":"https://api.github.com/users/chaniks/repos","events_url":"https://api.github.com/users/chaniks/events{/privacy}","received_events_url":"https://api.github.com/users/chaniks/received_events","type":"User","site_admin":false},"created_at":"2016-10-07T10:42:27Z","updated_at":"2016-10-07T10:42:27Z","body":"Also strange behavior of first(n)\r\n\r\nDoc says: (https://crystal-lang.org/api/0.19.3/Iterator.html#first%28n%3AInt%29-instance-method)\r\n> `def first(n : Int)`\r\n> Returns an iterator that only returns the first n elements of the initial iterator.\r\n\r\nBut:\r\n```crystal\r\niter = (1..5).each\r\niter.next\r\niter = iter.first(3)\r\niter.next # => 2\r\n```\r\n\r\nIt should be 1."}}
{"actor":{"display_login":"chaniks"}}