How to use -> in Luau

I was looking into the Fusion UI module and It uses some syntax Im not familiar with.

Hydrate(script.Parent.TextLabel) {
	Text = txt
}

Ive never seen a curly brace following a function call so I took a look at at the module itself to try and understand it.

Hydrate: (target: Instance) -> ((propertyTable: PubTypes.PropertyTable) -> Instance),

This however only gave me more questions. So, I read the Luau syntax page but the example they provided still didnt make it clear enough, only including this snippet and a little bit of text basically saying “Oh, yeah! You can do this too, but we’re not going to elaborate on it!”

local foo: (number, string) -> boolean

Im still just getting used to the Luau syntax and type checking. Been using Lua for ages but with the addition of Luau ive been getting lost everywhere and learning tons of new concepts, this being one of them.

That is the function type, the lexeme -> denotes the separation between the function arguments and its returned values.

1 Like

func {"a", "b"} is the same as func({"a", "b"})

Hydrate: (target: Instance) -> ((propertyTable: PubTypes.PropertyTable) -> Instance),

This says that Hydrate is a function which takes in an Instance, and returns another function which takes in properties and returns an Instance.

So

local fn = Hydrate(script.Parent.TextLabel) 

local instance = fn({
	Text = txt
})

foo would be called with a number and a string and return a boolean

1 Like

I’m not too sure if I’ve got this entirely correct, so correct me if I’m wrong.
“->” defines the return types of variables. In Luau, you use a “:” instead. So you could do this:

local function addNumbers(numberOne:number, numberTwo:number): (number) --we will return a number
    return numberOne + numberTwo --here is that number we will return
end

local answer = addNumbers(5, 7)
print(answer)

it’s just shorthand for for ({}). When passing a table to a function call you can omit the parantheses and it still knows it’s a function call.


As for → and :, those are just use to define types and return types