# Acting on an optional

**URL:** <https://forum.canton.network/t/acting-on-an-optional/3324>\
**Category:** App Development\
**Created:** [October 18, 2021, 5:55pm UTC](https://forum.canton.network/t/acting-on-an-optional/3324 "2021-10-18T17:55:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonid\_Rozenberg](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/leonid_rozenberg/32/48_2.png) [@Leonid\_Rozenberg](https://forum.canton.network/u/Leonid_Rozenberg)\
**Post date:** [October 18, 2021, 5:55pm UTC](https://forum.canton.network/t/acting-on-an-optional/3324/1 "2021-10-18T17:55:27Z")

</div>

I often want to use a function such as

```haskell
optionalA : Action m => b -> (a -> m b) -> Optional a -> m b
optionalA n _ None = pure n
optionalA _ f (Some x) = f x

```

but every time that I actually apply it, because the `Optional a` is the last argument it looks weird and I inline the `case` analysis instead. Should I break with convention and change the order of arguments? Are there other workarounds?

---

<div class="post-metadata">

**Author:** ![Stephen](https://yyz2.discourse-cdn.com/flex034/user_avatar/forum.canton.network/stephen/32/102_2.png) [@Stephen](https://forum.canton.network/u/Stephen)\
**Post date:** [October 18, 2021, 7:01pm UTC](https://forum.canton.network/t/acting-on-an-optional/3324/2 "2021-10-18T19:01:23Z")

</div>

It is common in the stdlib to have two names for the same function with different argument orders. For example, in `DA.Traversable`, you have `mapA`, for which one instance is `Action m => (a -> m b) -> Optional a -> m (Optional b)`, but the function `forA` is also provided, which has an instance `Action m => Optional a -> (a -> m b) -> m (Optional b)`.

See also `<$>` vs `<&>`. There’s no problem having different names with different argument orders for the same function, though if one is a member of a typeclass, the other should not be (as it is with the stdlib examples).

```haskell
import Prelude hiding (mapA)
import DA.Optional (fromOptional)
import DA.Traversable (mapA)

optionalA' : Action m => b -> (a -> m b) -> Optional a -> m b
optionalA' n f oa = fromOptional n <$> mapA f oa

```
