Avatar
値型のプロパティを一部書き換えたコピーを頻繁に作りたいときに extension Value { func with<Value>( _ kp: WritableKeyPath<Self, Value>, _ newValue: Value ) -> Self { var copy = self copy[keyPath: kp] = newValue return copy } } を用意すると let copy = value .with(\.name, "John") .with(\.address.countryName, "Japan") みたいにできて便利で、 SwiftSyntax はプロパティ毎の withXXX(_:) APIを全部捨ててこの汎用with(_:_:)に置き変えますよっていう。 https://github.com/apple/swift-syntax/pull/1253 (edited)
Instead, provide a single with function that takes a key path of the child you want to replace. This significatnly reduces the amout of code that is being generated for SwiftSyntax. While at it, al...