https://kotlinlang.org logo
Title
l

Luke

06/22/2022, 2:50 PM
In Arrow Optics, is there an equivalent of 'lift' but just to get the value? I have something like
val getId: (MyClass) -> String? = MyClass.somePath.id::getOrNull
, which works, but I would prefer to call a method instead of
::getOrNull
to return a lambda directly so I don't have to explicit the variable type.
s

simon.vergauwen

06/22/2022, 4:17 PM
l

Luke

06/22/2022, 5:32 PM
But
lift
generates a function to modify the source right? I want to generate a function to get the value in the source
s

simon.vergauwen

06/23/2022, 6:54 AM
Oh I see. I'm sorry. Then I think your best best would be to work with
::getOrNull
. I'm not sure what you mean with
to explicit the variable type
. Is it not simply returning
(MyClass) -> String?
?
l

Luke

06/23/2022, 2:04 PM
No, it returns a
KFunction1<MyClass, String?>
. I just assumed I couldn't use it as a lambda but I guess I can. Thanks for the help