let

R let<R>(

  1. R op(
    1. T
    )
)

Apply function op to this value and return the result.

This is useful for chaining operations and avoiding temporary variables. Also known as the "let" operation in Kotlin or "tap" in other languages.

Parameters:

  • op: Function that transforms this value into a result of type R

Returns: The result of calling op with this value

Example:

final length = 'hello world'
    .let((s) => s.split(' '))
    .let((words) => words.length); // Returns: 2

// Instead of: final text = 'hello world'; final words = text.split(' '); final length = words.length;

Implementation

R let<R>(R Function(T) op) => op(this);