Hacker News new | ask | show | jobs
by ToJans 1016 days ago
This reminds me of Haskell's 'functor' [1]

[1] https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-...

1 comments

Very much so, it’s a functor instance on some sort of tree, except the `map` includes a conditional dispatch.

It’s essentially

    fmap $ ap fromMaybe
Except this doesn’t quite work, I’m sure there’s a pointfree version, best I can achieve is

    \p -> fmap $ ap fromMaybe p
Which takes an `a -> Maybe a` and an `[a]`, and replaces all the values for which the callback returns `Some`, and leaves as-is all the values for which it returns `None`.

(I collapsed the `whereFn` and `updateFn` into a single one because there’s no reason not to)

You're looking for `fmap . ap fromMaybe`