Apply a function only if isJust
haskell
Solution
You can do this as long as type of `world` and `moveCreature (fromJust c) world` are same. You can use `maybe` from `Data.Maybe`.
moveMaybeCreature = maybe id moveCreature
Your first way of doing where you pattern match should also work just fine.
Problem
I am looking for a idiomatic way of doing ``` moveMaybeCreature Nothing world = world moveMaybeCreature (Just creature) world = moveCreature creature world ``` Or in other words ``` if isJust c then doSomething (fromJust c) w else w ``` I thought I could to it this way: ``` moveMaybeCreature c w = foldr moveCreature w (maybeToList c) ``` Can I do it without having to convert `Maybe Creature` to `[Creature]`?