Advertisement
ZivkicaI

HOFsandCurries

Nov 29th, 2019
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.52 KB | None | 0 0
  1. package part3Udemy
  2.  
  3. object HOFsandCurries extends App{
  4.  
  5.   // def compose[A,B,T](f:A=>B, g:T=>A):T=>B=  moze i vaka
  6.     def compose(f: Int => Int, g: Int=> Int):Int => Int=
  7.     x=>f(g(x))
  8.  
  9.   //def andThen[A,B,C](f: A => B, g: B => C): A => C =  moze i vaka
  10.     def andThen(f: Int => Int, g: Int => Int): Int => Int=
  11.     x=>g(f(x))
  12.  
  13.   val add2=(x:Int) => x+2
  14.   val times3= (x:Int) => x*3
  15.  
  16.   val composed=compose(add2,times3)
  17.   val ordered=andThen(add2,times3)
  18.  
  19.   println(composed(4))
  20.   print(ordered(4))
  21.  
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement