[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

[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!,

[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

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

2016-04-08 Thread Adriano Ferreira via swift-users
y.components = components >> return entity >> } >> func component(_: T.Type) -> T? { >> return self.components.first(T) >> } >> } >> >> // game: >> struct Character: Entity { >> // TODO: make

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

2016-05-09 Thread Adriano Ferreira via swift-users
t 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 >> <swift-users@swi

[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] Cannot invoke 'stride' with an argument list of type '(from: Int, to: Int, by: Int)'

2016-07-05 Thread Adriano Ferreira via swift-users
kson 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] 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 >

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 >