Avatar
first(where:) とかあるぐらいなので、こんなのも通るのかなと思ってるこの頃 extension Sequence { @inlinable public func indices( where predicate: (Element) throws -> Bool ) rethrows -> [Int] { return try self.enumerated().compactMap({ if try predicate($0.element) { return $0.offset } return nil }) } } let array = [1,2,3,4,5,6,7,8] print(array.indices(where: { $0 % 2 == 0})) //[1, 3, 5, 7]