18:25 | <nicolo-ribaudo> | Why doesn't reduce take a thisArg parameter? |
18:31 | <bakkot> | presumably because it already has a different optional parameter? |
20:00 | <Kris Kowal> | Indeed, and reduce is arity sensitive so you can’t throw another optional argument after it. |
20:01 | <Kris Kowal> |
|
20:04 | <Kris Kowal> | In a parallel universe where Pepsi and Coke products coëxist in peace, the basis argument of reduce is required and thisArg is optional on the end. |
20:05 | <bakkot> | it would not make sense to make the basis required; there are plenty of things which support some add/join/whatever operation but which do not have an identity |
20:08 | <bakkot> | (assuming by basis you mean the initial value, anyway) |
20:08 | <Kris Kowal> | Yeah, as in basis and recursive step . reduce is induction with a funny name. |
20:09 | <Kris Kowal> | Could be worse. Like, fold . |
20:09 | <bakkot> | fold is at least physically evocative |
20:10 | <Kris Kowal> | I’m speaking from a place of caffeine. Please take all above in jest. |
20:37 | <nicolo-ribaudo> | Thanks to both of you! |
20:38 | <nicolo-ribaudo> | I have another "why?" 😄 Why do we need to disallow line terminators between |
20:39 | <bakkot> | my guess - again just a guess - is to preserve the possibility of * as a prefix operator, as in yield\n*x |
20:40 | <bakkot> | though actually that doesn't really make the situation better, come to think |
20:40 | <bakkot> | yeah I dunno |
20:41 | <nicolo-ribaudo> | That operator screams "ASI hazard" very loudly :P |
20:42 | <bakkot> | eh, so does + |
20:42 | <bakkot> | +x === 1 && console.log('x is 1') |
20:42 | <bakkot> | I guess probably don't write that code though |