uCalc API Version: 2.1.3-preview.2 Released: 6/16/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: 

String Library

Class: 

String

Applies a transformation expression to each item in the string's internal list, creating a new list of results.

Syntax

Map(string, string)

Parameters

expression
string
The expression string to evaluate for each item. The item's value will be available in the variable specified by `variableName`.
variableName
string
(Default = "")
The name of the variable within the `expression` that will hold the value of the current item being processed. Defaults to 'x'.

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:

  1. Assigns the item's value to a temporary variable (named x by default, or as specified by variableName).
  2. Evaluates the provided expression string in the context of that variable.
  3. 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 Map is 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 map operates on arrays of native types. uCalc's Map operates on an internal list of tokenized string segments, giving it a more powerful context for text manipulation.

Examples