Untitled
raw download clone
SCALA
views 20
,
size 455 b
//zad 1
  def sum(l: List[Option[Int]]): Option[Int] = {
    @annotation.tailrec
    def suma(s : Int, t: List[Option[Int]]) : Option[Int] = {
      if(t.size <= 0){
        Some(s)
      }else{
        t.head match {
          case Some(value) => suma(s+value, t.tail)
          case None => suma(s, t.tail)
        }
      }
    }
    suma(0, l);
  }

  val x : List[Option[Int]] = List(Some(12),None, None,Some(16))
  println(sum(x))
close fullscreen
Login or Register to edit or fork this paste. It's free.