Is lambda expression available for Genie language?

In Vala, we do like this

my_func((a, b) => { /* code */ });

Is it possible to do the same with Genie?


AFAICS you can’t do that in Genie and instead have to define a separate function:

    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)
	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:


    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.