You are currently viewing kotlin.Result as return type in functions vs function literals?

kotlin.Result as return type in functions vs function literals?

Hi,Its known that kotlin.Result can’t be used as return type for functions;

So fun parseNumber(s: String) = runCatching { s.toInt() } will not compile.

But what I find weird is that it can be used in function literals, as follow:

val parseNumber:(String)->Result<Int> = {n-> runCatching{n.toInt()}}

or

val parseCatchingFn: (String)->Result<Int> = fun(n) = runCatching{n.toInt()}

will compile correctly, why and what’s the difference?

submitted by /u/alilosoft
[link] [comments]