Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
> On 11 Apr 2016, at 02:57, Jens Alfke wrote: > > Welcome to the world of bike-shedding. Love that :) milos___ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
Thanks, Jacob, for the links. Apple did take steps in this direction by spoiling us with a choice of random sources in the GameplayKit. I’m sure that after that initial effort, the GameplayKit team will continue to bring more power to the randomisation part of the framework. Only, that is not

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
> On 11 Apr 2016, at 02:17, Jens Alfke wrote: > > I’d argue that “random” is a broad concept with several possible > implementations. Which RNG does `sample` use? Pick a cryptographic one and it > might be too slow for some use cases; pick a fast one and it'd be > insufficiently random, makin

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
> On 10 Apr 2016, at 23:12, Jens Alfke wrote: > You can easily implement your own `sample` property. The very first email of this thread has a link to my example implementation. Here it is again if you mist it: http://stackoverflow.com/a/30285125/1409907

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
> On 10 Apr 2016, at 22:16, Erica Sadun wrote: > > I don't think general random sources are a good fit for core functionality I’m sorry, Erica, I still do not understand how your comments about “core functionality” reflect on my original question – have you seen it? Certainly, there is plenty

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
> On 10 Apr 2016, at 21:23, Erica Sadun wrote: > > I do not think it's the role of a core language to worry about things like > distributions, bias, and sampling. Why do you mention “the role of a core language” here? That was explicitly not the ambition of my question. I’m talking about exten

Re: [swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
Thank you, Jens, for your response. I do however disagree with both points you are making. First, you write that sampling collection elements at random is: > a pretty obscure feature But how can this be? When you teach students how to implement a card playing game in Swift, how do you shuffl

[swift-users] Sampling collections

2016-04-10 Thread Milos Rankovic via swift-users
In the playground: "works?".capitalizedString // error: value of type 'String' has no member 'capitalizedString' … but: import Foundation “works!”.capitalizedString // “Works!” Would it not be nice if all the following likewise worked: import Foundation (1..<4).sampl

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

2016-04-08 Thread Milos Rankovic via swift-users
>>>>var entity = self.init() >>>>entity.components = d >>>>return entity >>>>} >>>>func component(_: T.Type) -> T? { >>>>return self.components[T.name/* String(T) */] as?

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

2016-04-08 Thread Milos Rankovic via swift-users
> On 8 Apr 2016, at 15:12, Adriano Ferreira wrote: > > Milos, > > Thanks for taking a look at it, I appreciate you suggestion. > > It’s protocol-oriented, quite different from the idea I was trying to emulate > — the one provided by GameplayKit. > > Well, I tried it and it works great. Thou

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

2016-04-08 Thread Milos Rankovic via swift-users
My message bounced on account of size. I’m sorry if you receive multiple copies of this: > “If Limb is a Component, then a Spider entity needs eight of them…” That’s a fair question to ask. My intuition is that sporting a `Component` answers a question, “does it have this feature?” In the case

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

2016-04-08 Thread Milos Rankovic via swift-users
Hi Adriano, I’m glad if you are finding this useful. I’ll get back to you on `add` and `remove`, but just let me confirm with you: You actually want to allow multiple, say, `Health` components to be added to your `Character`? Most of the complication in my suggested code comes from trying to pr

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
Hi Erica, Wouldn’t this work for @tuuranton’s purposes? let allUInt8s = UInt8.min.stride(through: UInt8.max, by: 1) allUInt8s.dynamicType // StrideThrough.Type Array(allUInt8s).count // 256 for i in allUInt8s { i // 0...255 } milos > On 8 Apr 2016, at 13:48, tuuranton--- via swift-

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
In that case, at least make it lazy: let allUInt8s = UInt8.min.stride(through: UInt8.max, by: 1) allUInt8s.dynamicType // StrideThrough.Type Array(allUInt8s).count // 256 for i in allUInt8s { i // 0...255 } milos > On 8 Apr 2016, at 13:48, tuuranton--- via swift-users > wrote: > >

Re: [swift-users] Looping through all values between UInt8.min and UInt8.max

2016-04-08 Thread Milos Rankovic via swift-users
Would this work for you? extension UInt8 { var u: UInt { return UInt(self) } } for i in UInt8.min.u...UInt8.max.u { print(i) } milos > On 8 Apr 2016, at 10:50, tuuranton--- via swift-users > wrote: > > I forgot to mention that I really would like to have i have type UInt8 wi

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

2016-04-08 Thread Milos Rankovic via swift-users
.percent // 100 milos > On 8 Apr 2016, at 11:05, Milos Rankovic via swift-users > wrote: > > This is just a sketch. There may be issues down the line (I’ve indicated some > with `TODO`s), but it works and you can try it in the playground: > > // Swift 2.2 > > //

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

2016-04-08 Thread Milos Rankovic via swift-users
This is just a sketch. There may be issues down the line (I’ve indicated some with `TODO`s), but it works and you can try it in the playground: // Swift 2.2 // utility: extension Array { func first (_: T.Type) -> T? { for e in self where e is T { return e as? T }