daily pastebin goal
10%
SHARE
TWEET

Compose Scala

Lusien_Lashans Mar 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package exercises
  2.  
  3. //  while, return и var запрещены
  4. //  0.5 балла
  5. object Compose {
  6.  
  7.   def compose[A, B, C](f: B => C, g: A => B): A => C = {
  8.     f compose g
  9.   }
  10.  
  11.   //  реализуйте функцию
  12.   def composeFunc[R, T](f: R => T => T, g: (T => T) => R, h: R => String) = {
  13.     compose(h, compose(g , f))
  14.   }
  15.  
  16.   //  с помощью функции composeFunc и for'а выведите рез-т
  17.   val f: (Int => Double => Double) = (i: Int) => { (d: Double) => i * (math.Pi * d) }
  18.   val g: ((Double => Double) => Int) = (f: (Double => Double)) => f(42).toInt
  19.   val h: Int => String = (i: Int) => (i * 2).toString
  20.   val ints = List(1, 2, 3, 4)
  21.  
  22.   val rslt: List[String] =
  23.     for {
  24.       i <- ints
  25.     } yield (composeFunc(f, g, h).apply(i))
  26. }
  27.  
  28. object ComposeApp extends App {
  29.   import Compose._
  30.   println(rslt)
  31. }
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