3 ms·
Too many conference recordings without a touch on refactoring the broken mapped function ? Wish i could have a real `array.map` just like in javascript.
by revskill 5y ago
Too many conference recordings without a touch on refactoring the broken mapped function ?
Wish i could have a real `array.map` just like in javascript.
- ptx 5y agoScheme, which was an inspiration for JavaScript, works the same way Python does in this case. See page 57 of the spec: http://dspace.mit.edu/bitstream/handle/1721.1/5600/AIM-848.pdf http://dspace.mit.edu/bitstream/handle/1721.1/5600/AIM-848.p... That was written in 1985. If you're thinking of this as a mistake and waiting for it to be corrected, you're going to be waiting a long time. Edit: Although it would be awesome if Python had extension functions like Kotlin, which would make this super easy to fix (either in your own code or the standard library). But that would require static typing to be more baked into the core language.
- ivanivanovich 5y agowhy is it broken?
- revskill 5y agoIn common sense, u just need to put a function into map, right ? x.map(fn) In python, mapped takes some arguments that makes me confused in order and types of arguments. Secondly, it broke my thinking process.
- whymauri 5y agoHaving a different interface doesn't mean its broken...
- kzrdude 5y agoInline code completion/IDE integration can have it show the parameter names or docstring inline in the editor. That helps me with map, specifically. :) With that configured, a window pops up in Vim and says we have: map(func: Callable[[_T1], _S], iter1: Iterable[_T1], /) -> Iterator[_S] —————————————————————————————————————————————————————————————————————————————— map(func, *iterables) --> map object Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted. —————————————————————————————————————————————————————————————————————————————— There are things to criticize here. Note that the type hinting (this is Python 3.8 btw) doesn't agree with the full generality of the stated function interface (the multiple iterables part).
- rbonvall 5y agoIs this what you wish? ['10', '10', '10'].map(parseInt) === [10, NaN, 2]
- revskill 5y agoWhat's your point here ?