Kev
03/18/2024, 9:04 AMSam
03/18/2024, 9:10 AMKev
03/18/2024, 9:36 AMsimon.vergauwen
03/18/2024, 9:48 AMfun add(x: Int, y: Int): Int = x + y
fun Int.add(y: Int): Int = this + y
These functions are identical, we can even see that if we assign them using method referencing.
val f: KFunction2<Int, Int, Int> = ::add
val g: KFunction2<Int, Int, Int> = Int::add
Exact same KFunction
type, so using an extension function doesn't affect purity. If you access a database, then it should take database
as a parameter or live inside an interface where the impl has access to database
.Kev
03/18/2024, 1:25 PMCLOVIS
03/18/2024, 1:32 PMsuspend
keyword, so it is always clear whether a function is pure or not.
Otherwise, do try to keep it clear in the name (impure functions should be named after actions, e.g. sort
in the standard library which sorts in-place, vs sorted
which returns a sorted copy).