https://kotlinlang.org logo
#android
Title
# android
p

Pardeep Sharma

02/01/2023, 3:02 AM
Hello Team, I have a suspend function named 'build' that returns Either<Model, Error> and I'm this using member reference as: val res = builder::build where 'res' type = KSuspendFunction0<Either<Model, ApiError>> However, I am expecting 'res' type should be: KSuspendFunction0*<Model?,* <Either<Model, Error>>> whereas, in a normal scenario when I am calling: val res = builder.build() the 'res' type is as expected as Either<Model, Error>. Am I missing something?
e

ephemient

02/01/2023, 3:08 AM
builder::build
is bound to
builder
p

Pardeep Sharma

02/01/2023, 3:12 AM
Sorry, I did not get many hints. Could you please elaborate?
p

Pardeep Sharma

02/01/2023, 3:20 AM
I'd change the return type and calling way, It did not help much.
e

ephemient

02/01/2023, 3:23 AM
if the function call is
builder.build()
, then
builder::build
also takes no arguments. it is bound to `builder`: the receiver is already pre-set to
builder
, as in
{ builder.build() }
. why would you expect the type to contain an additional argument type?
on the other hand (assuming the type is named
Builder
),
Builder::build
is not bound to an instance, so it does take an argument, similar to
{ builder -> builder.build() }
. note the difference between a type and an instance on the left-hand side of
::
p

Pardeep Sharma

02/01/2023, 3:27 AM
I am passing builder::build call to a generic method as a param, that accepts:
Copy code
modelBuilder: suspend (model: T?) -> Either<T, Error>
e

ephemient

02/01/2023, 3:29 AM
if the function is normally called by
builder.build()
then where do you expect the
model
parameter to go?
✔️ 1
p

Pardeep Sharma

02/01/2023, 3:34 AM
Got it, I was missing an optional nullable param. Thanks much.
13 Views