[swift-dev] Scala updated equivalent
Alexandre Lopoukhine
superlopuh at gmail.com
Tue Dec 22 04:42:55 CST 2015
Hello everyone!
What do you all think about adding the equivalent of Scala’s update method to collections that have the insert() func? This would likely take the form of:
public func inserted(newElement: Self.Generator.Element, atIndex i: Self.Index) -> Self {
var modified = self
modified.insert(newElement, atIndex: i)
return modified
}
I’ve had to do this manually quite a lot in my various programs, where I’ve had to return an array or dictionary with just one element modified, and I have a feeling that I am not alone. I think that this is quite a natural way to go about things, and the addition would cut down on boilerplate code.
— Sasha
P.S. Alternatives could be “.withInserted(el, atIndex: i)” or “.with(el, insertedAtIndex: i)"
More information about the swift-dev
mailing list