Function.From
FunctionCreates a typed function wrapper that converts a unary function to match a specific function type signature.
Syntax
Function.From(functionType as type, function as function) as functionParameters
| Name | Type | Required | Description |
|---|---|---|---|
functionType | type | Yes | The function type that defines the parameter names and types for the new function. |
function | function | Yes | A unary function that receives a record of the named parameters. |
Return Value
function — A new function matching the specified type signature that delegates to the provided function.
Remarks
Function.From wraps a unary function (one that takes a single record argument) into a function with a typed multi-parameter signature. The wrapped function receives all named parameters as fields of a record.
This is useful for:
- Creating custom functions with documented parameter names and types that appear in the Power Query UI. - Building reusable function libraries where the parameter metadata is defined separately from the implementation.
The functionType defines the shape of the resulting function (parameter names, types, and return type). The inner function receives a record with field names matching the parameter names.
Examples
Example 1: Create a typed addition function
let
AddType = type function (a as number, b as number) as number,
AddFn = Function.From(AddType, (args) => args[a] + args[b]),
Result = AddFn(10, 32)
in
#table({"Expression", "Result"}, {{"AddFn(10, 32)", Result}})Expression | Result | |
|---|---|---|
| 1 | AddFn(10, 32) | 42 |