Scala functional programming gymnastics

后端 未结 13 978
悲&欢浪女
悲&欢浪女 2021-02-01 09:36

I am trying to do the following in as little code as possible and as functionally as possible:

def restrict(floor : Option[Double], cap : Option[Double], amt : D         


        
13条回答
  •  没有蜡笔的小新
    2021-02-01 10:21

    Not quite as terse as the scalaz version, but on the other hand, no dependencies,

    List(floor.getOrElse(Double.NegativeInfinity), cap.getOrElse(Double.PositiveInfinity), amt).sorted.apply(1)
    

提交回复
热议问题