Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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!


[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...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: