TypeFunction example: ImplictConvTargets

claptrap clap at trap.com
Wed Oct 7 08:13:14 UTC 2020


On Wednesday, 7 October 2020 at 02:33:21 UTC, Andrei Alexandrescu 
wrote:
> On 10/6/20 9:07 PM, claptrap wrote:
>> On Tuesday, 6 October 2020 at 23:39:24 UTC, H. S. Teoh wrote:
>>> On Tue, Oct 06, 2020 at 11:16:47PM +0000, claptrap via 
>>> Digitalmars-d wrote: [...]
>>>>
>>> I would write it like this:
>>>
>>>     int[] vals = [4,7,28,23,585,73,12];
>>>
>>>     int[] getMultiplesOf(int i)
>>>     {
>>>         return vals.filter!(v => (v % i) == 0).array;
>>>     }
>>>
>>> One line vs. 4, even more concise. ;-)
>> 
>> The point is to show language not library.
>
> That's a made-up restriction, and it's odd that it is being 
> discussed here as a virtue.

If you're trying to compare how the two features work in practice 
it's not going to be very illuminating if you hide all the 
workings behind a function call. Ie what good is

int[] getMultiplesOf(int i)
{
     return vals.tf_filter(v => (v % i) == 0);
}

vs...

int[] getMultiplesOf(int i)
{
     return vals.filter!(v => (v % i) == 0).array;
}

Yeah that helps a lot :)


More information about the Digitalmars-d mailing list