Re: to compose or hack?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: But it got me thinking, how often do people roll their own vs. trying to compose using existing Phobos nuggets? When there's not an obvious/simple way to do something by composing ranges, I tend to just give up and write

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 3:52 PM, Sebastiaan Koppe wrote: On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote: On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the

Re: to compose or hack?

2021-07-07 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 19:52:30 UTC, Sebastiaan Koppe wrote: Just lift each item in a range then: ```d import std; auto foo(string s, string sp, string j) @nogc { return s.splitter(sp).map!(i => only(i)).joiner(only(j)); } ``` Code golf: `map!(i => only(i))` can be shortened to

Re: to compose or hack?

2021-07-07 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 13:30:28 UTC, Steven Schveighoffer wrote: On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/7/21 5:54 AM, rassoc wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully).

Re: to compose or hack?

2021-07-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/6/21 11:42 PM, Jon Degenhardt wrote: On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: This is pretty minimal, but does what I want it to do. Is it ready for inclusion in Phobos? Not by a longshot! A truly generic interleave would properly forward everything else that

Re: to compose or hack?

2021-07-07 Thread rassoc via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully). Without considering the more general

Re: to compose or hack?

2021-07-06 Thread Jon Degenhardt via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: This is pretty minimal, but does what I want it to do. Is it ready for inclusion in Phobos? Not by a longshot! A truly generic interleave would properly forward everything else that the range supports (like `length`,

to compose or hack?

2021-07-06 Thread Steven Schveighoffer via Digitalmars-d-learn
So I have this situation where I need to split a string, then where the splits are, insert a string to go between the elements making a new range, all without allocating (hopefully). Looking around phobos I found inside the documentation of