@metreeca/core - v0.10.0
    Preparing search index...

    Function map

    • Applies a mapper to a value.

      Names an intermediate value inside the expression that consumes it, so a computation stays a single expression instead of splitting into a temporary variable and a statement, and the name is free to shadow the one the value was computed from, putting the raw value out of reach for the rest of the mapper.

      The mapper is always called and its result reported unchanged, whatever the value: an undefined value is handed on like any other, so reach for opt where it is to bypass the mapper instead.

      Type Parameters

      • V

        The type of the value to map

      • R

        The type of the value reported by mapper

      Parameters

      • value: V

        The value to hand on to mapper

      • mapper: (value: V) => R

        The mapper to apply to value

      Returns R

      The value computed from value by mapper; errors raised by mapper propagate to the caller unchanged

      function label(...tags: string[]): string { // the raw tags are unreachable past the mapper
      return map(tags.filter(tag => tag !== ""), tags => tags.length === 0 ? "untagged" : tags.join(", "));
      }