Min/max with Option[T] for possibly empty Seq?

后端 未结 10 1151
别那么骄傲
别那么骄傲 2021-01-31 14:03

I\'m doing a bit of Scala gymnastics where I have Seq[T] in which I try to find the \"smallest\" element. This is what I do right now:

val leastOrNo         


        
10条回答
  •  情书的邮戳
    2021-01-31 14:22

    In Haskell you'd wrap the minimumBy call as

    least f x | Seq.null x = Nothing
              | otherwise  = Just (Seq.minimumBy f x) 
    

提交回复
热议问题