Bug 2928 – Swap order of paramaters for std.range's "take"

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-05-03T14:49:00Z
Last change time
2015-06-09T01:26:25Z
Assigned to
andrei
Creator
bus_dbugzilla

Comments

Comment #0 by bus_dbugzilla — 2009-05-03T14:49:33Z
According to the docs, in std.range, "take" takes the range as its second parameter and 'n' as the first parameter. This ordering should be swapped, 1. to be consistent with stride, advance, retreatN, and cycle, and 2. to allow the syntax "a.take(n)" like with advance.
Comment #1 by andrei — 2009-05-03T15:36:00Z
Undecided. take is inspired from Haskell et al where the range comes last.
Comment #2 by jarrett.billingsley — 2009-05-03T15:48:55Z
Keep in mind that Haskell's parameter ordering is based on partial application, a feature that D obviously does not have.
Comment #3 by andrei — 2009-05-03T16:06:49Z
(In reply to comment #2) > Keep in mind that Haskell's parameter ordering is based on partial application, > a feature that D obviously does not have. > Sort of does: import std.functional, std.range, std.stdio; void main() { auto a = [ 1, 2, 3 ][]; alias curry!(take, 2) take2; foreach (e; take2(a)) { writeln(e); } } But I agree there are good arguments in favor of swapping arguments.
Comment #4 by lutger.blijdestijn — 2009-12-08T06:18:52Z
Please consider this also for replicate* and any other functions (though replicate and take are the only ones I could find.) Note that in haskell's prelude, there are many functions that also can be found in phobos, such as splitAt and until, for which the same argument could be made. Haskell does seem to be more consistent in argument ordering, always the predicate first and then the list, this makes it easy to remember. It's a bit weird that when uniform function call syntax will be implemented, this will work: iota(0,10).stride(2).until(8) but this won't work: iota(0,10).stride(2).take(4) I'd rather give up currying myself to make this work, even for the benefit of consistency alone. * note that std.string.repeat is defined as string repeat(string s, size_t n);
Comment #5 by k-foley — 2010-01-22T16:58:03Z
What is the status on this? I would like to see it it changed to Take!(R) take(R)(R input, size_t n); Take!(Repeat!(T)) replicate(T)(T value, size_t n);
Comment #6 by andrei — 2010-01-22T17:16:25Z
I'll change that soon. Thanks!
Comment #7 by k-foley — 2010-05-01T16:00:42Z