| Thread overview |
|---|
October 23, 2015 Lazy generic std.algorithm.replace() | ||||
|---|---|---|---|---|
| ||||
Is there a reason why std.algorithm doesn't provide a lazy range implementation of replace()?
I'm aware this isn't difficult to express using `map` like, for instance,
auto replace(S, F, T)(S, F from, T to)
{
return s.map!(a => a == from ? to : a);
}
but I prefer syntactic sugars.
While at it we could make use of variadics to enable syntax such as
assert(equal("do_it".replace('_', ' ',
'd', 'g',
'i', 't',
't', 'o',
"go to");
along with optional predicate (as usual).
What do you say?
| ||||
October 23, 2015 Re: Lazy generic std.algorithm.replace() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Friday, 23 October 2015 at 11:23:55 UTC, Nordlöw wrote: > Is there a reason why std.algorithm doesn't provide a lazy range implementation of replace()? Sample implementation at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1939 for one replacement pair. | |||
October 23, 2015 Re: Lazy generic std.algorithm.replace() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Friday, 23 October 2015 at 11:53:06 UTC, Nordlöw wrote: > https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1939 > > for one replacement pair. Made it variadic at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1950 | |||
October 23, 2015 Re: Lazy generic std.algorithm.replace() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Friday, 23 October 2015 at 21:44:28 UTC, Nordlöw wrote: > On Friday, 23 October 2015 at 11:53:06 UTC, Nordlöw wrote: >> https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1939 >> >> for one replacement pair. > > Made it variadic at > > https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1950 Added hashed based version at https://github.com/nordlow/justd/blob/master/algorithm_ex.d#L1999 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply