uCalc API Version: 2.1.3-preview.2 Released: 6/17/2026
Warning
uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.
Map
Method
Product:
Class:
Applies a transformation expression to each item in the string's internal list, creating a new list of results.
Syntax
Parameters
Return
String
Returns the current String object, now representing the new list of transformed results, to allow for method chaining.
Remarks
The Map method is a powerful functional programming tool that transforms each item in a uCalc.String's internal list. This method is used when a uCalc.String object is in a "list state," which occurs after operations like Find() or ListOfTokens().
It iterates through each item in the list, executes a given expression on it, and replaces the original list with the new list of transformed results.
How It Works
For each item in the list, the Map method:
- Assigns the item's value to a temporary variable (named
xby default, or as specified byvariableName). - Evaluates the provided
expressionstring in the context of that variable. - Collects the result of each evaluation.
After iterating through all items, the internal list within the uCalc.String object is replaced by this new collection of results.
Built-in Context Variables
Inside the expression, you have access to several context-aware variables:
- The item variable (default
x): The value of the current item being processed. Index: The zero-based index of the current item in the list.Count: The total number of items in the list.
💡 Why uCalc? (Comparative Analysis)
Map is a classic higher-order function found in many languages, but uCalc's implementation is unique due to its dynamic, string-based nature.
vs. C# LINQ
Select:var numbers = new List<int> { 1, 2, 3 };var squared = numbers.Select(x => x * x);LINQ is compile-time and type-safe. uCalc's
Mapis dynamic at runtime. The transformation logic is provided as a string, which can be constructed or loaded from user input, configuration files, or other dynamic sources.vs. JavaScript
Array.prototype.map:let numbers = [1, 2, 3];let squared = numbers.map(x => x * x);While also dynamic, JavaScript's
mapoperates on arrays of native types. uCalc'sMapoperates on an internal list of tokenized string segments, giving it a more powerful context for text manipulation.