Extension compose gives wrong value

The following program gives a good result and a bad result.
Why is the extension failing ? What is specific wrong ?


def compose1[A, B, C](f: B => C, g: A => B): A => C =
  x => f(g(x))

def add2(n:Int):Int = n+100
def mul3(n:Int):Int = n*33
extension [A,B] (x: A => B) def compose2[C](g:B => C): A=> C = y => g(x(y))

@main private def main(args: String*): Int =
  val x= (compose1 (mul3,add2)) (0)
  val y= add2 compose mul3
  val z= y(0)
  println(x) // OK
  println(z) // ERROR FUNCTION mul3 not run
  0

I tried this and it seems to run just fine:

3300
100

Since 100 + 33 * 0 = 100

Did you mean to write compose2 for compose in the last line?

1 Like

Yes it works indeed fine.
I just made an error in the order.
It had to be :


val y= mul3 compose add2