Description
Inspired by Context Functions, I decided to practice my bad taste on simulating the it
anonymous function parameter. But it doesn't work.
Minimized code
object Kotlin:
def it[T](using t: T) = t
def fun[T, U](fn: T ?=> U)(x: T): U = fn(using x)
import Kotlin.{fun, it}
List(1).map(fun(it + 1))
Output
|List(1).map(fun(it + 1))
| ^^^^
|value + is not a member of Int, but could be made available as an extension method.
|
|One of the following imports might fix the problem:
|
| import math.BigDecimal.int2bigDecimal
| import math.BigInt.int2bigInt
| import math.Numeric.BigDecimalAsIfIntegral.mkNumericOps
| import math.Numeric.BigDecimalIsFractional.mkNumericOps
| import math.Numeric.BigIntIsIntegral.mkNumericOps
| import math.Numeric.IntIsIntegral.mkNumericOps
| import Long.long2double
| import math.BigDecimal.long2bigDecimal
| import Long.long2float
| import math.BigInt.long2bigInt
|
Expectation
This code should compile as it
has already been inferred as Int
.
Workaround
Providing type arguments to fun
works.
List(1).map(fun[Int, Int](it + 1))