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

Popular posts from this blog

python - Referencing Data From a 2D Histogram -

php - MySQL LIMIT results with INNER JOIN with more than 2 tables -

c# - Derived UserControl layout resets after build -