I cannot get reduce to chain with filter. What am I doing wrong? Here’s my code:
let names = [“Larry”, “Nancy”, “Chet”, “Heather”, “Trey”, “Rocco”]
let chained = names.filter{$0.count > 4}.reduce(into: String()) {
result, name in
result += name
}
The playground complains;
error: MyPlayground.playground:6:42: error: cannot invoke ‘reduce’ with an argument list of type ‘(into: String, (_, _) → _)’
let chained = names.filter{$0.count > 4}.reduce(into: String()) {
But when I do it separately, this works:
let longNames = names.filter {$0.count > 4}
let allNames = longNames.reduce(into: String()) {
result, name in
result += name
}