Bug 7896 – Sequence slicing

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-04-13T02:06:00Z
Last change time
2015-06-09T01:31:16Z
Assigned to
nobody
Creator
daniel350

Comments

Comment #0 by daniel350 — 2012-04-13T02:06:23Z
Rather then simply building an array from scratch, perhaps it should be possible to do the following: auto my_odds = sequence!("n * 2 + 1")()[0...100] Unless there is another way to do this.
Comment #1 by dmitry.olsh — 2012-04-13T02:33:47Z
Somehow take(sequence!("n * 2 + 1")(), 100) doesn't cut it or what?
Comment #2 by k.hara.pg — 2012-04-13T02:46:20Z
(In reply to comment #0) > Rather then simply building an array from scratch, perhaps it should be > possible to do the following: > > auto my_odds = sequence!("n * 2 + 1")()[0...100] > > Unless there is another way to do this. With range concept, slicing operator with boundaries has no meaning. You should use std.range.take and std.array.array like follows: auto my_odds = array(take(sequence!("n * 2 + 1")(), 100)); And if you use 2.059beta or later, you can use UFCS syntax: auto my_odds = sequence!("n * 2 + 1")().take(100).array();
Comment #3 by bearophile_hugs — 2012-04-13T04:21:59Z
(In reply to comment #2) > With range concept, slicing operator with boundaries has no meaning. I think the point of this enhancement request is to give a meaning to that syntax. So: someRange[x .. y] becomes syntax sugar for calling a function like: itertools.islice(someRange, x, y) of Python: http://docs.python.org/library/itertools.html#itertools.islice the idea of giving some more syntax support to D lazy ranges isn't that bad.
Comment #4 by dmitry.olsh — 2012-04-13T04:37:09Z
The syntax is supported. It's just up to implementer of a range if he can provide opSlice meaningfully.
Comment #5 by daniel350 — 2012-08-12T05:50:52Z
Comment #6 by github-bugzilla — 2012-09-16T19:17:33Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/d9e1a501ecba84426ddde161dce7408e719a1a8b Added std.range.Sequence slicing (Issue 7896) See http://d.puremagic.com/issues/show_bug.cgi?id=7896 for more information. https://github.com/D-Programming-Language/phobos/commit/1b645ba717aadf175b93ab344394284008ff5d7d Merge pull request #748 from RommelVR/master Added std.range.Sequence slicing (Issue 7896)