SHARE
TWEET

Poly Scala

Lusien_Lashans Mar 17th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package exercises
  2. //  while, return и var запрещены
  3. //  try catch не использовать
  4. //  1 балл
  5.  
  6. object Poly {
  7.  
  8.   type Set[T] = T => Boolean
  9.  
  10.   def contains[T](s: Set[T], elem: T): Boolean = {
  11.     s(elem)
  12.   }
  13.  
  14.   def singletonSet[T](elem: T): Set[T] = {
  15.     x: T => x == elem
  16.   }
  17.  
  18.   def union[T](s: Set[T], t: Set[T]): Set[T] = {
  19.     x: T => (contains(s, x) || contains(t, x))
  20.   }
  21.  
  22.   def intersect[T](s: Set[T], t: Set[T]): Set[T] = {
  23.     x: T => (contains(s, x) && contains(t, x))
  24.   }
  25.  
  26.   def diff[T](s: Set[T], t: Set[T]): Set[T] = {
  27.     x: T => (contains(s, x) && !(contains(t, x)))
  28.   }
  29.  
  30.   def filter[T](s: Set[T], p: T => Boolean): Set[T] = {
  31.     x: T => p(x) && s(x)
  32.   }
  33.  
  34. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top