As a side effect of SE-0110 tuple unsplating was removed from the language.
While this claims to make tooling like the type checker faster, it deals quite a blow to expressivity.
Filterting dictionaries is just an example and maybe not the best. However I hope the point gets across. Let's compare to other languages.
Examples of pattern matching in closure parameters:
let eighteenOrMore = ["Tom" : 33, "Rebecca" : 17, "Siri" : 5].filter { arg in
let (_, age) = arg // Awkward :| No tuple unsplatting
return age >= 18
}
// OR
// Still No tuple unsplatting
let eighteenOrMore = ["Tom" : 33, "Rebecca" : 17, "Siri" : 5].filter { $0.1 >= 18 }
// OR
// Somewhat better
let eighteenOrMore = ["Tom" : 33, "Rebecca" : 17, "Siri" : 5].filter {(arg: (name: String, age: Int)) in arg.age >= 18 }
mapOf("Tom" to 33, "Rebecca" to 17, "Siri" to 5).filter({ (_, age) -> age >= 18 })
{name: age for name, age in {'Tom': 33, 'Rebecca': 17, 'Siri': 5}.iteritems() if age >= 18 }
{"Tom" => 33, "Rebecca" => 17, "Siri" => 5}.select{ |_, age| value >= 18 }
filter (\(_,age) -> age>= 18) [("Tom", 33), ("Rebecca", 17), ("Siri", 5)]
(filter (fn [[_ age]] (>= age 18)) {"Tom" 33 "Rebecca" 17 "Siri" 5})
List(("Tom" , 33), ("Rebecca", 17), ("Siri", 5)).filter{ case (_, age) => age >= 18}
[("Tom", 33), ("Rebecca", 17), ("Siri", 5)].into_iter().filter(|&&(_, age)| age >= 18);
Object.entries({Tom: 33, Rebecca: 17, Siri: 5}).filter(([_, age]) => value >= 18)
[T || {_, Age} = T <- [{"Tom", 33}, {"Rebecca", 17}, {"Siri", 5}], Age > 18].
(remove-if-not #'(lambda (x) (>= (cadr x) 18)) '(("Tom" 30) ("Rebecca" 17) ("Siri" 5)))
@blender Can you give me an example of such a function, for example in Ruby?
I mean, in Ruby
select
is explicitly defined onHash
asselect {|key, value| block} → a_hash
so it definitely expect a block with 2 arguments, not a block with a single argument being magically unsplat…Also, the terms you are using (functions with more than 2 parameters) are revealing. Functions taking functions with 2 arguments are not affected by SE-110. Only functions taking functions with one argument of type tuple (2-tuple or 3-tuple or N-tuple) are affected), so I really think you're blinded by that distinction and that if we had that extension on
Dictionary
in stdlib already you'd never have realised that change by SE-110, because 99% of the use cases it affects today (and I totally agree the way it affects them today is bad, I'm not disputing that, but again to improve that let's go forward, not backwards) arefilter/forEach/map/flatMap
calls on…Dictionary
, which are the main functions in stdlib that accept functions taking a single tuple argument rather than 2 distinct arguments.BTW I think I personally never had to use that feature (that you seem to miss with SE110) with tuples of more than 2 elements. The only thing that SE-110 are gonna affect I think are functions that took a single argument of type tuple with 2 items, and 99% of those functions are the ones on
Dictionary
, for which we could (and should) have a better signature anyway (one that takes 2 parameters instead of a single tuple). So besides those cases (which I agree SE-110 now makes look bad at call site, I don't deny that at all) I don't think there are much more cases — even in other languages tbh — where you're gonna need them. And those cases (functions onDictionary
should be addressed by improving their signatures anyway.