haskell - Minimum of Two Maybes -
i want minimum of 2 maybe values, or if 1 nothing non-nothing one, or return nothing if both inputs nothing. can write simple function this, suspect there way without writing custom function. sorry, if petty question, there simpler way using custom function?
minmaybe :: ord => maybe -> maybe -> maybe minmaybe nothing b = b minmaybe nothing = minmaybe (just a) (just b) = $ min b
you cannot use applicative
, or monad
instance this, since nothing
in contexts have total result being nothing
. being said, term "simpler" highly opinionated, , function fine is.
Comments
Post a Comment