Re:Swift System Is Now Open Source
by saagarjha on Friday September 25, 2020 @08:08PM
(#24595320)
That where is not a one-off construct, it's used with switch statements:
Or generic constraints:
If you so wish, you can always use any of the functional constructs as well, as in
[ Parent
| on HN ]
So it looks like it's a general modifier to a range type, so can be used where those work. That's slightly better, but if filter exists, why not just use that?
One of the biggest criticisms that Perl gets is that there's so many different ways to do things, and that's somewhat deserved, so the question is what does "where" offer that "filter" doesn't other than another keyword and concept you have to learn to understand the language? What's the point if it's not really that much more expressive or clear?
> struct Vector<T> where T: Numeric
Is this really the same thing? This seems like a case where the same word is used to mean something else, even if they are loosely conceptually the same.
Re:Swift System Is Now Open Source
by solidsnack9000 on Saturday September 26, 2020 @12:27AM
(#24596412)
It isn't actually a modifier to a range type -- it modifies other constructs, like looping or conditionals. The examples don't show it but literally any condition can go in the where clause, even something like `where random() % 7 == 2`.