Facebook
From Burly Hog, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 242
  1. import scala.annotation.tailrec
  2.  
  3. object Main5 extends App {
  4.     type Pred[A] = A => Boolean;
  5.     @tailrec
  6.     def forall[A](a : Seq[A])(pred: (A) => Boolean) : Boolean = {
  7.         if (a.isEmpty)
  8.             true;
  9.         else if (!pred(a.head))
  10.             false
  11.         else
  12.             forall(a.tail)(pred)
  13.     }
  14.  
  15.     val (nieparzyste : Pred[Int]) = (x : Int) => x % 2 != 0;
  16.     var a = Seq(1,3,5,7);
  17.     var b = Seq(1,3,6,7);
  18.  
  19.     println("Dla " + a.mkString("[", ", ", "]") + ":  " + forall(a)(nieparzyste));
  20.     println("Dla " + b.mkString("[", ", ", "]") + ":  " + forall(b)(nieparzyste));
  21. }