Re: [swift-users] Simplify chained calls

2016-06-28 Thread Dan Loewenherz via swift-users
On Tue, Jun 28, 2016 at 9:58 PM, Erica Sadun wrote: > Most everyone is doing two passes, one to get the minimum value, another > to get its index. > I aesthetically prefer using enumerate to do both at once. > > -- E > Makes sense. Here’s a revision. It’s not as simple, but it does just one pass

Re: [swift-users] Simplify chained calls

2016-06-28 Thread Erica Sadun via swift-users
> > On Jun 28, 2016, at 8:18 PM, Dan Loewenherz via swift-users > wrote: > > I’m not sure if you wanted to stick with the pure functional approach, but > here’s an alternative that uses Range to take care of most of the work. > > func selectionSort(_ array: [Int]) -> [Int] { > guard let m

Re: [swift-users] Simplify chained calls

2016-06-28 Thread Dan Loewenherz via swift-users
I’m not sure if you wanted to stick with the pure functional approach, but here’s an alternative that uses Range to take care of most of the work. func selectionSort(_ array: [Int]) -> [Int] { guard let minValue = array.min(), let index = array.index(of: minValue) else { return []

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Dave Abrahams via swift-users
on Tue Jun 28 2016, Andrew Trick wrote: >> On Jun 28, 2016, at 9:32 AM, Jordan Rose via swift-users >> wrote: >> >> >>> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: >>> > >>> Thanks for your reply. It didn’t clear up everything, though. The >>> official documentation says "Weak referenc

Re: [swift-users] LazyCollection.map()

2016-06-28 Thread Dmitri Gribenko via swift-users
On Tue, Jun 28, 2016 at 6:07 PM, Aaron Bohannon wrote: > AH! I wasn't familiar enough with the LazyCollectionType protocol to > realize that its map() function had a different signature. > > So, presumably, if I pass a non-throwing closure, the compiler will choose > the lazy map(). However, it'

Re: [swift-users] LazyCollection.map()

2016-06-28 Thread Aaron Bohannon via swift-users
AH! I wasn't familiar enough with the LazyCollectionType protocol to realize that its map() function had a different signature. So, presumably, if I pass a non-throwing closure, the compiler will choose the lazy map(). However, it's not immediately obvious to me why it would be chosen. Is it be

Re: [swift-users] Simplify chained calls

2016-06-28 Thread Aaron Bohannon via swift-users
I think that's about as simple as you can make it unless you allow yourself to remove more than one element at a time when the minimum appears more than once. Here's the question I find interesting: what's the simplest way to change that code into a version based on lazy collections? After all, t

Re: [swift-users] LazyCollection.map()

2016-06-28 Thread Dmitri Gribenko via swift-users
On Tue, Jun 28, 2016 at 3:37 PM, Aaron Bohannon via swift-users wrote: > Does the code below have a well-defined behavior? It invokes the eager map() that is available on Array.lazy. Array.lazy is a collection, so it has an eager map() from the Collection protocol. The lazy map() does not accept

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Andrew Trick via swift-users
> On Jun 28, 2016, at 9:32 AM, Jordan Rose via swift-users > wrote: > > >> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: >> >> Thanks for your reply. It didn’t clear up everything, though. The official >> documentation says "Weak references do not affect the result of this >> function.”,

[swift-users] LazyCollection.map()

2016-06-28 Thread Aaron Bohannon via swift-users
Does the code below have a well-defined behavior? struct Nope: ErrorType {} func f(i: Int) throws -> Int { guard i < 5 else { throw Nope() } return i } do { let _ = try Array(0 ..< 10).lazy.map(f) print("lazy") } catch (let e) { print(e) } _

Re: [swift-users] Default bounds subscript for BidirectionalCollection

2016-06-28 Thread Tim Vermeulen via swift-users
No problem! But no, count is correct. From the docs: “endIndex: The collection's "past the end" position---that is, the position one greater than the last valid subscript argument." > On 28 Jun 2016, at 22:45, Roy Henderson wrote: > > Definitely not trying to correct your code Tim - but, being

[swift-users] Default bounds subscript for BidirectionalCollection

2016-06-28 Thread Tim Vermeulen via swift-users
I expected the following code to compile: struct Wrapper: BidirectionalCollection { var elements: [Element] var startIndex: Int { return 0 } var endIndex: Int { return elements.count } func index(after index: Int) -> Int { return index + 1 } func index(before ind

Re: [swift-users] Swift 3 equivalent of dispatch_barrier_async

2016-06-28 Thread Daniel Dunbar via swift-users
The new spelling is: queue.async(flags: .barrier) { ... } - Daniel > On Jun 28, 2016, at 12:24 PM, Eric Miller via swift-users > wrote: > > I tried searching github's swift-evolution for "dispatch_barrier_async", but > don't see a mention of it. > > Can I migrate this directly to swift 3,

[swift-users] Swift 3 equivalent of dispatch_barrier_async

2016-06-28 Thread Eric Miller via swift-users
I tried searching github's swift-evolution for "dispatch_barrier_async", but don't see a mention of it. Can I migrate this directly to swift 3, or do I need a larger refactor involving serial queues? ```swift let myConcurrentQueue = DispatchQueue(label: "concurrentQ", attributes: . concurrent) d

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Joe Groff via swift-users
> On Jun 28, 2016, at 9:32 AM, Jordan Rose via swift-users > wrote: > > >> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: >> >> Thanks for your reply. It didn’t clear up everything, though. The official >> documentation says "Weak references do not affect the result of this >> function.”,

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Dave Abrahams via swift-users
on Tue Jun 28 2016, Jordan Rose wrote: >> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: >> >> Thanks for your reply. It didn’t clear up everything, though. The >> official documentation says "Weak references do not affect the >> result of this function.”, which suggests that weak (and unowne

Re: [swift-users] Checking whether an object is uniquely referenced, using a weak reference to it

2016-06-28 Thread Jordan Rose via swift-users
> On Jun 27, 2016, at 18:52, Tim Vermeulen wrote: > > Thanks for your reply. It didn’t clear up everything, though. The official > documentation says "Weak references do not affect the result of this > function.”, which suggests that weak (and unowned) references intentionally > aren’t counte

[swift-users] Simplify chained calls

2016-06-28 Thread Adriano Ferreira via swift-users
Hi everyone! I’m experimenting with this functional selection sort code and I wonder if anyone could help me simplify the portion indicated below. // Swift 3 func selectionSort(_ array: [Int]) -> [Int] { guard array.count > 1, let minElement = array.min() else { return array }

Re: [swift-users] Xcode8 Swift 3.0 new API

2016-06-28 Thread Dennis Weissmann via swift-users
I am also interested in the new API and cannot find it on Darwin :( Will this be available in seed 2? - Dennis Sent from my iPhone > On Jun 18, 2016, at 1:57 PM, Kostiantyn Koval via swift-users > wrote: > > Hi everyone, > > In "What's New in Foundation for Swift” WWDC session there were ann