(0 ..< numberOfQueries) .lazy .map { _ in Int(readLine()!)! } .map { array[(rotatedFirstIndex + $0) % endIndex] } .forEach { print($0) }0 ..< numberOfQueries is a CountableRange: a struct which you can think of as similar to an array of consecutive values, but for which there's no actual storage of these values. Its lazy property didn't need to be used, but I wanted to prevent an array being stored by each of the maps chained after it. You'll find information about lazy and forEach in the Swift Standard Library reference. The omission of parentheses around the closures provided to the map and forEach calls is known as trailing closure syntax, which is explained in The Swift Programming Language guide, and I strongly recommend you read that guide.The code could have been written as follows, but I wanted a little practice at writing in a more functional style.for _ in 0 ..< numberOfQueries { let queryIndex = Int(readLine()!)! let value = array[(rotatedFirstI
Topic:
Programming Languages
SubTopic:
Swift
Tags: