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
>
> 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
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 []
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
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'
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
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
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
> 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.”,
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)
}
_
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
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
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,
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
> 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.”,
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
> 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
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
}
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
19 matches
Mail list logo