In Vala, we do like this
my_func((a, b) => { /* code */ });
Is it possible to do the same with Genie?
In Vala, we do like this
my_func((a, b) => { /* code */ });
Is it possible to do the same with Genie?
Hej,
AFAICS you can’t do that in Genie and instead have to define a separate function:
init
my_func(callback, "", "")
delegate DelegateType (a: string, b: string) : bool
def my_func (callback:DelegateType, a: string, b: string)
return callback(a, b)
def callback( a:string, b:string ):int
return 0
seems like a good compromise. Thanks
def lambda_rto() : bool
return true
def async public read_to_end_async() : string?
result:string = null
new Thread of bool ("rte", lambda_rto)
yield
return result
Genie does have a syntax for lambda expressions but it only works with assignment, not when passing as an argument to a function. Here is an updated version of @Cogitri’s example:
[indent=4]
init
cb: DelegateType = def (a, b)
return 0
my_func(cb, "", "")
delegate DelegateType (a: string, b: string) : int
def my_func (callback: DelegateType, a: string, b: string): int
return callback(a, b)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.