The map() function applies a function across vectors, lists, or data frames efficiently. Syntax: map(.x, .f, ...) where .x is data, .f is function, ... for extra args. Examples: square vector elements via ~.x^2, get means of column across list of data frames with ~mean(.x$y), apply custom functions to rows/cols like df$z <- map_dbl(df, add_cols).
Comprehensions are currently compiled as nested functions, which provides isolation of the comprehension’s iteration variable, but is inefficient at runtime. This PEP proposes to inline list, dictionary, and set comprehensions into the code where they are defined, and provide the expected isolation by pushing/popping clashing locals on the stack.
Last: F Strings will support some common use cases that broke interpolation in the past, like f'{ myDict['myKey'] }' and f"{'n'.join(a)}"
And yes, many of them are #bugs that would be #agonizing to find by other routes. Your unit test #probably doesn't try passing a #float to that #function you wrote that you only considered using ints with - but with hints, mypy will find that "one weird way" that a float value returned from somewhere else could get passed into the function.
Type hints in code - used well and consistently, no using "#Any" to shut mypy up - make me 50% more productive, I think. </anecdote>
At first, I didn’t like type hints in #Python, but we decided to give it a go since our codebase really exploded in the last couple of years. All I can say now is we should have done it earlier. I still find it unbealivable that we discovered so many small bugs that went unnoticed all these years.
Static type #checkers do help find #bugs - even ones that would be nasty to try to debug after hitting them in use.
But you can also use them to enforce #contracts, if you prefer that to duck typing (not built-in). A lot of Pythonistas will hold their nose at that, but it can be useful to "die loudly and early" when someone else passes the wrong #types to your #function.
For quite some time I’ve been collecting some tips and tricks in #Swift and #SwiftUI that I’d like to share with you. I’ll share a new tip every day and hope to last until at least WWDC
I'll also post same content on Twitter in case you prefer it over Mastodon
Day 17
When debugging or testing, knowing where a function was called from can be crucial. Use #file, #line, and #function literals to get filename, line, and function name. These can be used in any function, and passed as default parameters to other functions