Thread overview |
---|
October 10, 2015 Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to string replaceWhole(string a) { switch (x) { case "a": return "1"; case "b": return "2"; default: return x; } } ? Desired interface y = x.replaceWhole!("a","x", "b","y", "c","z") or perhaps y = x.replaceWhole!(tuple("a","x"), tuple("b","y"), tuple("c","z")) kind of like "a".among!("a", "b", "c") but for replacements. |
October 10, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 10 October 2015 at 16:19:53 UTC, Nordlöw wrote: > Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to Found it: http://dlang.org/phobos/std_algorithm_comparison.html#predSwitch An alias would be perhaps be motivated to make newcomers easier grap that this can be used for whole replacements. |
October 10, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 10 October 2015 at 16:42:52 UTC, Nordlöw wrote:
> Found it:
>
> http://dlang.org/phobos/std_algorithm_comparison.html#predSwitch
>
> An alias would be perhaps be motivated to make newcomers easier grap that this can be used for whole replacements.
Ahh, but this doesn't use a hash-table because it doesn't support taking its arguments as CT-params...so that doesn't qualify.
Maybe we should add a new CT-param-only overload for `predSwitch` similar to `among`?
Destroy!
|
October 11, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 10 October 2015 at 16:19:53 UTC, Nordlöw wrote:
> Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to
>
> string replaceWhole(string a)
> {
> switch (x)
> {
> case "a": return "1";
> case "b": return "2";
> default: return x;
> }
> }
>
> ?
>
> Desired interface
>
> y = x.replaceWhole!("a","x",
> "b","y",
> "c","z")
>
> or perhaps
>
> y = x.replaceWhole!(tuple("a","x"),
> tuple("b","y"),
> tuple("c","z"))
>
>
> kind of like
>
> "a".among!("a", "b", "c")
>
> but for replacements.
There was something like this proposed quite awhile ago (can't remember what it was, might've been extending unary/binaryFun to accept an AA), but it was rejected.
|
October 11, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Sunday, 11 October 2015 at 00:16:44 UTC, Meta wrote:
> There was something like this proposed quite awhile ago (can't remember what it was, might've been extending unary/binaryFun to accept an AA), but it was rejected.
With static foreach in a switch we can do better. I'll put together a solution.
|
October 11, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Sunday, 11 October 2015 at 05:06:04 UTC, Nordlöw wrote: > On Sunday, 11 October 2015 at 00:16:44 UTC, Meta wrote: >> There was something like this proposed quite awhile ago (can't remember what it was, might've been extending unary/binaryFun to accept an AA), but it was rejected. > > With static foreach in a switch we can do better. I'll put together a solution. Here's a solution: https://github.com/nordlow/justd/blob/f8519e8a1af68bc25cc00c6ef12d13efa791250c/comparison_ex.d |
October 12, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Saturday, 10 October 2015 at 16:19:53 UTC, Nordlöw wrote:
> Is there an algorithm somewhere in Phobos which performs when possible a replacement/substitution based on a variadic definition of replacements using hash-table search similar to
>
> string replaceWhole(string a)
> {
> switch (x)
> {
> case "a": return "1";
> case "b": return "2";
> default: return x;
> }
> }
>
> ?
>
> Desired interface
>
> y = x.replaceWhole!("a","x",
> "b","y",
> "c","z")
>
> or perhaps
>
> y = x.replaceWhole!(tuple("a","x"),
> tuple("b","y"),
> tuple("c","z"))
>
>
> kind of like
>
> "a".among!("a", "b", "c")
>
> but for replacements.
It would also be nice to have a splitter that can split on any of a number of conditions being fulfilled in a similar vein.
|
October 13, 2015 Re: Hash-Table-Based Multiple Arguments Replacement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Sunday, 11 October 2015 at 11:17:29 UTC, Nordlöw wrote: > Here's a solution: > https://github.com/nordlow/justd/blob/f8519e8a1af68bc25cc00c6ef12d13efa791250c/comparison_ex.d Latest version contains a few fixes: https://github.com/nordlow/justd/blob/master/comparison_ex.d |
Copyright © 1999-2021 by the D Language Foundation