Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Adriano Ferreira via swift-users
Hi there! Ole Begeman offers here (take a look at the bottom of the page) an interesting consideration about converting between half-open and closed ranges. As of now, it seems the way to go is by overloading… import Foundation func random(from

Re: [swift-users] generic function called recursively not compiling

2016-08-07 Thread Adriano Ferreira via swift-users
Hey Ray, Feel free to take a look at the swift-3 branch of this repo , too. There are several quick sort implementations there, from classic to Swift-y! Cheers, — A > On Aug 4, 2016, at 12:02 PM, Ray Fix via swift-users > wrote: > > > I filed r

Re: [swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

2016-07-05 Thread Adriano Ferreira via swift-users
wn Erickson wrote: >> >>> Int conforms to Strideable byway of Integer <- SignedInteger <- Int (not >>> exactly sure how it will be once the integer proposal is implemented but it >>> will still be strideable). >>> >>> -Shawn >>

Re: [swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

2016-07-05 Thread Adriano Ferreira via swift-users
T.Stride) > -> StrideTo <> > > Int does not conform to Strideable. > > Adopted By > > CGFloat > Decimal > Double > Float > Float80 > String.UTF16View.Index > UnsafeMutablePointer > UnsafePointer > > ​In Swift 2.2, > > @warn_unuse

[swift-users] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

2016-07-04 Thread Adriano Ferreira via swift-users
Hi everyone! I’m converting some code to Swift 3 and got this issue? Does anybody know what’s going on? Here’s the code, before and after conversion: // Swift 2.2 extension Int { // Repeat a block of code from `self` up to a limit func up(to upper: Int, by step: Int = 1, @noescape

Re: [swift-users] Simplify chained calls

2016-06-30 Thread Adriano Ferreira via swift-users
Hi Tod, thanks for sharing your ideas. Much appreciated! Feel free to take a look at my playground where I explore many other alternative implementations. https://github.com/adrfer/Sort/tree/swift-3 Best, — A > On Jun 30, 2016, at 11:32 AM, Tod Cunningham via swift-users > wrote: > > This

[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] Appending '[element]' recursively

2016-06-27 Thread Adriano Ferreira via swift-users
Thanks Dmitri. If use typecasting it seems to work again. Take a look below: // Swift 3 func quickSort(_ array: [Int]) -> [Int] { guard array.count > 1 else { return array } let (pivot, rest) = (array.first!, array.dropFirst()) let lessThan = rest.filter({ $0 < pivot })

[swift-users] Appending '[element]' recursively

2016-06-27 Thread Adriano Ferreira via swift-users
Hi everyone! I’m migrating some code from Swift 2.2. to Swift 3 and something weird happened. Is this is a bug or I’m missing something? // Swift 2.2 func quickSort(_ array: [Int]) -> [Int] { guard array.count > 1 else { return array } let (pivot, rest) = (array.first!, arr

Re: [swift-users] @noescape

2016-05-17 Thread Adriano Ferreira via swift-users
Nate, Let me know if you’d like some help to write a draft/proposal. I’d be happy to help :P Best, — A > On May 17, 2016, at 3:04 PM, Adriano Ferreira via swift-users > wrote: > > Here’s the related thread > https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-

Re: [swift-users] @noescape

2016-05-17 Thread Adriano Ferreira via swift-users
Here’s the related thread https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151214/003748.html Cheers, — A > On May 16, 2016, at 12:43 PM, Nate Birkholz via swift-users > wrote: > > Well that

Re: [swift-users] Guarding against an empty sequence

2016-05-09 Thread Adriano Ferreira via swift-users
way you could check if it returns `nil` the first > time that you call it (i.e. the sequence is empty) and return whatever you > desire in that case > > — Shane S > > >> On May 8, 2016, at 7:16 PM, Adriano Ferreira via swift-users >> mailto:swift-users@sw

[swift-users] Guarding against an empty sequence

2016-05-08 Thread Adriano Ferreira via swift-users
Hi everyone! I’m working on the following method: extension SequenceType { /// Check if `predicate` is true for all elements of `self` /// /// - Parameter predicate: The predicate called on each element of `self` /// /// - Returns: True iff every element in `self` satisfies `

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
} >>>> >>>> protocol Entity { >>>>static func with(_: Component...) -> Self >>>>// TODO: make get only >>>>// also should be a set-by-type really, but that would >>>>// force `Component` to be a class (which

Re: [swift-users] Checking/getting custom objects from a collection

2016-04-08 Thread Adriano Ferreira via swift-users
gt; } >> func component(_: T.Type) -> T? { >> return self.components.first(T) >> } >> } >> >> // game: >> struct Character: Entity { >> // TODO: make private >> var components: [Component] = [] >>

[swift-users] Checking/getting custom objects from a collection

2016-04-07 Thread Adriano Ferreira via swift-users
Hi everyone! I’m experimenting with Entity-Component Systems and I’d appreciate if you could help me working on how to check/get custom objects from a collection. The idea is to verify if an entity contains a particular component and, if s

Re: [swift-users] In pursuit to a more idiomatic Swift

2016-01-04 Thread Adriano Ferreira via swift-users
still 1TBS <https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS>? if array.isEmpty { return false } Both styles are present in Apple’s Swifts projects on GitHub. Best, — A > On Dec 21, 2015, at 11:01 PM, Adriano Ferreira via swift-users > wrote: > > Hi everyone! > &g

[swift-users] In pursuit to a more idiomatic Swift

2015-12-21 Thread Adriano Ferreira via swift-users
Hi everyone! While learning and in pursuit a to more idiomatic Swift, I put together a playground where I’ve been experimenting with some simple sorting techniques. I’d appreciate any ideas on how to improve those algorithms into a more Swift-y form. So, here is the repository