You are building a functional data processing library for analytics pipelines. The library needs to support lazy evaluation, where transformations are not executed until actually needed. This pattern is common in big data frameworks like Apache Spark and functional programming languages.
The key requirement: each map() must return a new immutable LazyArray object that accumulates transformations without executing them. Only when a terminal operation like indexOf() is called should the transformations actually run.
`
arr = LazyArray([10, 20, 30, 40, 50])
lazy = arr.map(lambda x: x * 2)
result = lazy.indexOf(40) # Returns 1 (20 * 2 = 40)
chain1 = arr.map(lambda x: x * 2) # Doubling chain2 = arr.map(lambda x: x + 5) # Adding 5
chain1.indexOf(40) # Returns 1 (independent) chain2.indexOf(15) # Returns 0 (independent) `
Lazy evaluation: Functions are not called during map(), only during indexOf()
Immutability: Each map() returns a new LazyArray without modifying existing ones
Independence: Multiple chains from the same base must be independent
Chaining: Support multiple map() calls in sequence