What does ! Stand for in map! and filter! function calls?

Dennis dkorpel at gmail.com
Sun Jun 2 17:53:51 UTC 2019


On Sunday, 2 June 2019 at 16:39:57 UTC, Rnd wrote:
> Is it not possible in the language to have template map 
> function also to called as map(x=>... ?

That would be slower, and std.algorithm generally disallows easy 
but slow functions.

In Java, you can sort a linked list. In D, sort requires an array 
(or random access range).
D's `uniq` removes duplicates, but assumes the input range is 
sorted.

Of course you can do myLinkedList.array.sort.uniq but it's not as 
easy as myLinkedList.uniq because that hides all the stuff that 
is required to happen behind the scenes.

It may be less beginner friendly, but I've also seen newcomers 
come with a question among the lines of 'I'm trying out the 
language, why is my little benchmark slower than equivalent 
Javascript' after which they're told 'don't use dmd, don't use 
80-bit floats, use these compiler flags' etc. So it's a trade-off 
between ease of use by default and performance by default.

A clear error message on `map` without ! is the way to go in my 
opinion.


More information about the Digitalmars-d-learn mailing list