"Rule" (Compiled Type)
"Rule"::[tykey,tyvalue]
represents a type with specified types for key and value.
Details
- "Rule" can be used in Typed and related constructs to specify a type.
- "Rule" objects are automatically memory managed.
- The key and value of a "Rule" can have any compiled type.
Constructors
- Rules can be created with Rule (->, ) in compiled code.
Properties
- First[rule] returns the first element of a rule.
- Last[rule] returns the last element of a rule.
- Information[rule,"KeyType"] for rule of type "Rule"::[tykey,tyvalue] gives tykey.
- Information[rule,"ValueType"] for rule of type "Rule"::[tykey,tyvalue] gives tyvalue.
Conversions
- Rule expressions can be converted into compiled code elements with the type "Rule"::[tykey,tyvalue] if the first element can be converted into the type tykey and the last element can be converted into the type tyvalue.
- "Rule" compiled elements can be converted into Rule expressions.
From Expressions
To Expressions
Examples
Basic Examples (1)
An instance of "Rule" can be created in and returned from compiled code:
cf = FunctionCompile[Function[{Typed[k, "Integer64"], Typed[v, "String"]}, k -> v]]Call the function with integer and string arguments and return a rule:
cf[ 5, "Value"]Enter a rule expression and return the first element:
cf = FunctionCompile[Function[{Typed[r, "Rule"::["Integer64", "String"]]}, First[r]]]cf[5 -> "text"]Enter a rule expression and return the last element:
cf = FunctionCompile[Function[{Typed[r, "Rule"::["Integer64", "String"]]}, Last[r]]]cf[5 -> "text"]See Also
Tech Notes
Related Guides
History
Introduced in 2024 (14.1)