<p dir="ltr">+1. This is very functional. Need to drill home the point that arrays have copy semantics in the intro swift docs though, if we start going in this direction. </p>
<br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 22, 2015, 7:12 AM Dmitri Gribenko via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Moving to swift-evolution.<br>
<br>
On Tue, Dec 22, 2015 at 2:42 AM, Alexandre Lopoukhine via swift-dev<br>
<<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>> wrote:<br>
> Hello everyone!<br>
><br>
> 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:<br>
><br>
> public func inserted(newElement: Self.Generator.Element, atIndex i: Self.Index) -> Self {<br>
> var modified = self<br>
> modified.insert(newElement, atIndex: i)<br>
> return modified<br>
> }<br>
><br>
> 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.<br>
><br>
> — Sasha<br>
><br>
> P.S. Alternatives could be “.withInserted(el, atIndex: i)” or “.with(el, insertedAtIndex: i)"<br>
> _______________________________________________<br>
> swift-dev mailing list<br>
> <a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br>
> <a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>>*/<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>