+Use LINQ for filtering and transformation
An existing iterable needs no new iterator class just to filter and transform its items. C# LINQ composes traversal by receiving a predicate in Where and a transformation function in Select. This example uppercases only track names beginning with in and leaves the input array unchanged.
C#
using System;
using System.Linq;
var tracks = new[] { "intro", "outro", "interlude" };
// Where filters, Select transforms, and ToArray enumerates and stores the results now.
string[] labels = tracks
.Where(track => track.StartsWith("in", StringComparison.Ordinal))
.Select(track => track.ToUpperInvariant())
.ToArray();
Console.WriteLine(string.Join(",", labels));
Console.WriteLine(string.Join(",", tracks));
TypeScript
const tracks = ["intro", "outro", "interlude"];
// Array filter and map evaluate immediately and return new arrays.
const labels = tracks
.filter(track => track.startsWith("in"))
.map(track => track.toUpperCase());
console.log(labels.join(","));
console.log(tracks.join(","));
INTRO,INTERLUDE
intro,outro,interlude
These examples use strings in memory. LINQ Where and Select run during enumeration, with ToArray choosing when to enumerate; TypeScript array filter and map evaluate immediately. Both select and uppercase the same ASCII track names here without modifying the source. Functional syntax alone does not prevent external calls or shared-state mutation.
Microsoft: Introduction to LINQ queries