4 ms·
> Unpacking doesn't let you specify default values if cardinality doesn't match Functional languages that have pattern matching have wildcard matches that allo
by bmitc 5y ago
> Unpacking doesn't let you specify default values if cardinality doesn't match
Functional languages that have pattern matching have wildcard matches that allow you to explicitly handle things that don't match as expected and also have tail matching for lists.
> nor can you extract dictionaries by keys
I'm not exactly sure what you mean here, but you can definitely do that for records in F# and maps/structs in Elixir. It's done all the time.
- bobbylarrybobby 5y agoI think the parent comment is referring to how you can do e.g., `let {x, y, z} = point` (JS, object/dictionary) or `let Point {x, y, z} = point} (Rust, struct) but in Python your only option is `x = point.x; y = point["y"]` etc
- BiteCode_dev 5y agoIndeed. Now you can do: import operator foo, bar, baz = operator.itemgetter('foo', 'bar', 'baz')(mapping) But it's verbose, inelegant, and doesn't handle missing values.
- bmitc 5y agoI misread their first sentence. I see now that they’re lamenting what I mentioned not being in Python. I was thinking they meant in general and not just in Python.