www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Docs for `Group` type

reply Bahman Movaqar <Bahma BahmanM.com> writes:
When using `chunkBy` (unary pred) the result is a list of tuples.  Each
tuple holds a key and a `Group` which belong to that key.
Where can I find the docs for this `Group` type (I have already tried
searching library on dlang.org)?

Thanks,
-- 
Bahman
Jul 11 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Tuesday, 12 July 2016 at 04:25:26 UTC, Bahman Movaqar wrote:
 When using `chunkBy` (unary pred) the result is a list of 
 tuples.  Each
 tuple holds a key and a `Group` which belong to that key.
 Where can I find the docs for this `Group` type (I have already 
 tried
 searching library on dlang.org)?

 Thanks,
The 'Group' type is an implementation detail -- a type used internally -- that you aren't supposed to care about. All you need to care about is that it's a range. The documentation for chunkBy [1] explains what the return type is. [1] https://dlang.org/phobos/std_algorithm_iteration.html#.chunkBy
Jul 11 2016
parent reply Bahman Movaqar <Bahma BahmanM.com> writes:
On 07/12/2016 11:06 AM, Mike Parker wrote:
 The 'Group' type is an implementation detail -- a type used internally
 -- that you aren't supposed to care about. All you need to care about is
 that it's a range. The documentation for chunkBy [1] explains what the
 return type is.
 
 [1] https://dlang.org/phobos/std_algorithm_iteration.html#.chunkBy
Thanks. Now since I can't do `takeOne` on `Group`[1], exactly what kind of range is `Group`? [1] Error: no property 'takeOne' for type 'Group' -- Bahman
Jul 12 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Tuesday, 12 July 2016 at 08:03:53 UTC, Bahman Movaqar wrote:
 On 07/12/2016 11:06 AM, Mike Parker wrote:
 The 'Group' type is an implementation detail -- a type used 
 internally -- that you aren't supposed to care about. All you 
 need to care about is that it's a range. The documentation for 
 chunkBy [1] explains what the return type is.
 
 [1] 
 https://dlang.org/phobos/std_algorithm_iteration.html#.chunkBy
Thanks. Now since I can't do `takeOne` on `Group`[1], exactly what kind of range is `Group`? [1] Error: no property 'takeOne' for type 'Group'
When you downloaded DMD, you also received the source to Phobos, so you can see for yourself. The only Group type I see the chunkBy implementations is at [1] (the link to the github viewer probably won't point to the same place for long, but you should be looking in the the version of ChunkByImpl for forward ranges). It's a forward range. Do you have some sample code that shows the error? [1] https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d#L1608
Jul 12 2016
parent reply Bahman Movaqar <Bahma BahmanM.com> writes:
On 07/12/2016 01:01 PM, Mike Parker wrote:
 Do you have some sample code that shows the error?
Yes. I'm working on Stockman[1] a playground to learn D. In file `etl.d`, line 110 [2], if I change the line to auto refInvoice = group[1].takeOne(); the file will not compile. I have attached the compile error to this message. Thanks, -- Bahman [1] https://github.com/bahmanm/stockman-d [2] https://github.com/bahmanm/stockman-d/blob/master/source/etl.d#L110
Jul 12 2016
next sibling parent reply Edwin van Leeuwen <edder tkwsping.nl> writes:
On Tuesday, 12 July 2016 at 11:40:48 UTC, Bahman Movaqar wrote:
 On 07/12/2016 01:01 PM, Mike Parker wrote:
 Do you have some sample code that shows the error?
Yes. I'm working on Stockman[1] a playground to learn D. In file `etl.d`, line 110 [2], if I change the line to auto refInvoice = group[1].takeOne(); the file will not compile. I have attached the compile error to this message. Thanks,
What does group.writeln; output? That should give you a good sense of what is going on.
Jul 12 2016
parent Bahman Movaqar <Bahma BahmanM.com> writes:
On 07/12/2016 04:21 PM, Edwin van Leeuwen wrote:
 On Tuesday, 12 July 2016 at 11:40:48 UTC, Bahman Movaqar wrote:
 On 07/12/2016 01:01 PM, Mike Parker wrote:
 Do you have some sample code that shows the error?
Yes. I'm working on Stockman[1] a playground to learn D. In file `etl.d`, line 110 [2], if I change the line to auto refInvoice = group[1].takeOne(); the file will not compile. I have attached the compile error to this message. Thanks,
What does group.writeln; output? That should give you a good sense of what is going on.
That's a good trick to know. Thanks. -- Bahman
Jul 12 2016
prev sibling parent reply ag0aep6g <anonymous example.com> writes:
On 07/12/2016 01:40 PM, Bahman Movaqar wrote:
 Yes.  I'm working on Stockman[1] a playground to learn D.
 In file `etl.d`, line 110 [2], if I change the line to
      auto refInvoice = group[1].takeOne();
 the file will not compile.  I have attached the compile error to this
 message.
Do you also add the import of takeOne? takeOne is not a range primitive, but a function that works on ranges. Need to import it in order to use it.
Jul 12 2016
parent Bahman Movaqar <Bahma BahmanM.com> writes:
On 07/12/2016 04:23 PM, ag0aep6g wrote:
 On 07/12/2016 01:40 PM, Bahman Movaqar wrote:
 Yes.  I'm working on Stockman[1] a playground to learn D.
 In file `etl.d`, line 110 [2], if I change the line to
      auto refInvoice = group[1].takeOne();
 the file will not compile.  I have attached the compile error to this
 message.
Do you also add the import of takeOne? takeOne is not a range primitive, but a function that works on ranges. Need to import it in order to use it.
Stupid me! Thanks :-) -- Bahman
Jul 12 2016