Я работаю с функциональной быстрой библиотекой на игровой площадке и выполняю некоторые манипуляции с клавишами.
Когда я бегу:
prop (\ User.favoriteFoods) <<< карта <<< prop (.name) </p>
Я получаю:
((String) -> String) -> (__lldb_expr_18.User) -> __lldb_expr_18.User
The functions I'm using are defined as follows:
// Backwards composition
public func <<< <A, B, C>(_ f: @escaping (B) -> C, g: @escaping (A) -> B) -> ((A) -> C) {
return { a in
f(g(a))
}
}
func prop<Root, Value>(_ kp: WritableKeyPath<Root, Value>) -> (@escaping (Value) -> Value) -> (Root) -> Root {
return { update in
{ root in
var copy = root
copy[keyPath: kp] = update(copy[keyPath: kp])
return copy
}
}
}
public func map<A, B>(_ f: @escaping (A) -> B) -> ([A]) -> [B] {
return { $0.map(f) }
}
struct Food {
var name: String
}
struct Location {
var name: String
}
struct User {
var favoriteFoods: [Food]
var location: Location
var name: String
}
let user = User(
favoriteFoods: [
Food(name: "Tacos"),
Food(name: "Nachos")
],
location: Location(name: "Brooklyn"),
name: "Blob"
)