3 ms·
True, depending on your language, you can probably get the imperative version to be shorter than my pseudo-C implementation. But that accumulating function you
by tmhedberg 14y ago
True, depending on your language, you can probably get the imperative version to be shorter than my pseudo-C implementation.
But that accumulating function you're passing to reduce? That's essentially just a JavaScript version of the bind (>>=) operator for Maybe. In fact, in Haskell, I'd express what you wrote as:
foldl (>>=) x [foo, bar, baz, quux]
foldl is Haskell's version of reduce, so that's almost exactly the same as your code. You're using a monad to shorten your code, you're just not being obvious about it!
- Peaker 14y ago[foo, bar, baz, quux] might be problematic if the types of these functions are not homogenous. foo >=> bar >=> baz >=> quux is ok and >=> is not a much-worse separator than , here...