Haskell guard sequence | Hugonweb Annotated Link Bibliography
https://entropicthoughts.com/non-obvious-haskell-idiom-guard-sequence
*> action -- Perform action if condition is true else fail
guard condition $> value -- Return value if condition is true else fail
guard condition <$ guard condition -- Like the 1st line, but switched around value
This can effectively make sure a condition is true before doing something or returning a value.
Keep in mind "failure" can mean lots of things depending on the surrounding Applicative. It could mean returning Nothing, or raising an exception.
You will need the following imports to do this:
import Control.Mondad (guard)
import Data.Functor ((*>),($>),(<$))