Function Library (Fn)
Linked with the "fn" type.
Library for working with and calling functions, linked to the 'fn' type.
Example Usage
#[main]
fn main() {
const f = ():str => 'hello';
assert_eq(Fn.call(f), 'hello');
assert_eq(f.call(), 'hello');
assert_eq(f(), 'hello');
}Fn.attributes(func: fn) -> map
Get a map of attributes (name & value) that this function has, if any.
const func: fn = self.hi; // #[hi] fn hi() {}
assert_eq(func.attributes(), {"hi": null});Fn.call(func: fn, ..) -> unknown
Call this function, using any arguments given after the function itself (some library functions can take N arguments, this is one of them).
const func: fn = (name: str):str => "Hi, " + name;
assert_eq(func.call("Bob"), "Hi, Bob");Fn.call_expanded(func: fn, ..) -> unknown
Call this function, using any arguments given after the function itself. However, if an argument is a collection (ex. list), expand the list values out as arguments themselves.
const func: fn = (name: str):str => "Hi, " + name;
assert_eq(func.call_expanded(["Bob"]), "Hi, Bob");Fn.data(func: fn) -> data
Get the data pointer for this function.
const func: fn = self.hi;
assert(func.data().exists());Fn.has_attribute(func: fn, name: str) -> bool
Returns true if the given function has an attribute with the given name.
const func: fn = self.hi; // #[hi] fn hi() {}
assert(func.has_attribute("hi"));Fn.id(func: fn) -> str
Get the data ID for this function (shorthand for "func.data().id()").
const func: fn = self.hi;
assert_eq(func.id(), func.data().id());Fn.is_async(func: fn) -> bool
Is this function async? This is just shorthand for checking if an "async" attribute exists (what makes a func async).
const func: fn = self.hi; // async fn hi() {}
assert(func.is_async());Fn.name(func: fn) -> str
Get the name of this function.
const func: fn = self.hi; // fn hi() {}
assert_eq(func.name(), "hi");Fn.obj(func: fn) -> obj
Get the first object found that references this function.
const func: fn = self.hi;
assert_eq(func.obj(), self);Fn.objs(func: fn) -> list
Get a list of all objects that this function is attached to.
const func: fn = self.hi;
assert_eq(func.objs(), [self]);Fn.params(func: fn) -> list
Get a list of expected parameters for this function (tuple containing the name and type).
const func: fn = self.hi; // fn hi(a: int) {}
assert_eq(func.params(), [("a", "int")]);Fn.return_type(func: fn) -> str
Get the return type for the given function.
const func: fn = self.hi; // fn hi() -> int { 42 }
assert_eq(func.return_type(), "int");Last updated
Was this helpful?