Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-09-09 Thread Dave Abrahams via swift-evolution
on Fri Aug 18 2017, Erica Sadun wrote: On Aug 17, 2017, at 9:29 PM, Taylor Swift wrote: On Thu, Aug 17, 2017 at 9:06 PM, Erica Sadun via swift-evolution > wrote: On Aug

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-19 Thread Daryle Walker via swift-evolution
> On Aug 17, 2017, at 1:06 PM, Erica Sadun via swift-evolution > wrote: > > Also, for those of you here who haven't heard my previous rant on the > subject, I dislike using map for generating values that don't depend on > transforming a domain to a range. (It has

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-18 Thread Taylor Swift via swift-evolution
On Fri, Aug 18, 2017 at 1:23 PM, Erica Sadun wrote: > I want to avoid breaking math. > it’s not that deep,,, the `for _ in 0 ..< n` loop is exactly the same thing except more verbose. In fact, that’s how your proposed ` Array.init(count:generator:)` would be implemented.

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-18 Thread Erica Sadun via swift-evolution
> On Aug 17, 2017, at 9:29 PM, Taylor Swift wrote: > On Thu, Aug 17, 2017 at 9:06 PM, Erica Sadun via swift-evolution > > wrote: > >> On Aug 17, 2017, at 6:56 PM, Xiaodi Wu >

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Erica Sadun via swift-evolution
> On Aug 17, 2017, at 7:38 PM, Xiaodi Wu wrote: > > On Thu, Aug 17, 2017 at 8:25 PM, Erica Sadun > wrote: > `repeatElement((), count: 5)` is better than `1 ... 5`, but `Count(3).map({ > UIView() })` is far more elegant.

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Xiaodi Wu via swift-evolution
On Thu, Aug 17, 2017 at 8:25 PM, Erica Sadun wrote: > `repeatElement((), count: 5)` is better than `1 ... 5`, but > `Count(3).map({ UIView() })` is far more elegant. I'd still probably go > with an array initializer or `5.elements(of: UIView())`. I don't think I'm >

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Erica Sadun via swift-evolution
`repeatElement((), count: 5)` is better than `1 ... 5`, but `Count(3).map({ UIView() })` is far more elegant. I'd still probably go with an array initializer or `5.elements(of: UIView())`. I don't think I'm overstating how common this pattern is, and `Array(repeating:count:)` feels _close_ but

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Robert Bennett via swift-evolution
Xiaodi, you pretty much took the words out of my mouth. I was going to suggest a Count collection whose Element was Void and with the sole initializer init(_ count: Int). The type would just contain its count and pretty much fake its collection interface, in the sense that no elements are

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Xiaodi Wu via swift-evolution
On Thu, Aug 17, 2017 at 8:06 PM, Erica Sadun wrote: > > On Aug 17, 2017, at 6:56 PM, Xiaodi Wu wrote: > > On Thu, Aug 17, 2017 at 7:51 PM, Erica Sadun wrote: > >> What people are doing is taking a real set of values (1, 2, 3, 4,

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Erica Sadun via swift-evolution
What people are doing is taking a real set of values (1, 2, 3, 4, 5, for example), then discarding them via `_ in`, which is different from `Void -> T` or `f(x) = 0 * x`. The domain could just as easily be (Foo(), "b", , UIColor.red, { x: Int in x^x }). There are too many semantic shifts away

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Xiaodi Wu via swift-evolution
This is, I would argue, much too limiting in the way of semantics and not at all required by “map”. It’s unclear to me how _any_ result with reference semantics or any function with side effects could be used in a way that comports with that definition. On the other hand, just as y = 0x is a

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Max Moiseev via swift-evolution
> On Aug 17, 2017, at 10:05 AM, Erica Sadun via swift-evolution > wrote: > > Also, for those of you here who haven't heard my previous rant on the > subject, I dislike using map for generating values that don't depend on > transforming a domain to a range. (It has

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Erica Sadun via swift-evolution
Also, for those of you here who haven't heard my previous rant on the subject, I dislike using map for generating values that don't depend on transforming a domain to a range. (It has been argued that `_ in` is mapping from `Void`, but I still dislike it immensely) Here are the ways that I

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Tony Allevato via swift-evolution
On Thu, Aug 17, 2017 at 9:20 AM Ross O'Brien wrote: > (0..<3).map{ _ in UIView() } - map already returns an Array. > > Array((0..<3).map{ _ in UIView() }) is redundant. > Ah, right, thanks for pointing that out. I couldn't remember off the top of my head whether it

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Ross O'Brien via swift-evolution
(0..<3).map{ _ in UIView() } - map already returns an Array. Array((0..<3).map{ _ in UIView() }) is redundant. I've fallen foul before, of trying to create an array of six buttons and getting an array of one button six times; I think that should be easier. But if each button corresponds to an

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Tony Allevato via swift-evolution
Couldn't this be rewritten more simply today as: Array((0..<3).map { index in MyView(forIndex: index) }) And the version that doesn't need the index could be written: Array((0..<3).map { _ in UIView() }) The AnyIterator approach posted above is also nice—I wouldn't have thought of that

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Jonathan Hull via swift-evolution
The closure should go on the end though… > On Aug 17, 2017, at 8:40 AM, Christopher Kornher via swift-evolution > wrote: > > We might as well add the index to the call so elements can be created from > other lists, etc. > > Array(repeatedlyCalling: { (index:Int)

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Rintaro Ishizaki via swift-evolution
I don't think it's worthwhile adding new API. I think this is simple enough: let views = Array(AnyIterator(UIView.init).prefix(3)) 2017-08-17 21:04 GMT+09:00 Robert Bennett via swift-evolution < swift-evolution@swift.org>: > Alternatively, instead of replacing the current definition with an >

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Robert Bennett via swift-evolution
Alternatively, instead of replacing the current definition with an autoclosure version, we could leave the current version in place and add a version taking a function. This could be especially useful when you’ve defined a function like `makeMySpecialKindOfButton() -> UIButton` that does a lot

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Haravikk via swift-evolution
> On 17 Aug 2017, at 10:38, Adrian Zubarev via swift-evolution > wrote: > > This is a small pitch which I will abandon if there is not much appetite for > such improvement. ;) > > I would like to propose an improvement to an initializer of all collection > types

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Adrian Zubarev via swift-evolution
In terms of functionality yes potentially a breaking change, because the behavior would change for objects that were initialized through the passed expression. Personally it always bugged me that it does not work for objects and forced map usage over a range to create an array of different

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Xiaodi Wu via swift-evolution
This would be very source-breaking, no? On Thu, Aug 17, 2017 at 04:47 Jonathan Hull via swift-evolution < swift-evolution@swift.org> wrote: > +1 > > On Aug 17, 2017, at 2:38 AM, Adrian Zubarev via swift-evolution < > swift-evolution@swift.org> wrote: > > This is a small pitch which I will abandon

Re: [swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Jonathan Hull via swift-evolution
+1 > On Aug 17, 2017, at 2:38 AM, Adrian Zubarev via swift-evolution > wrote: > > This is a small pitch which I will abandon if there is not much appetite for > such improvement. ;) > > I would like to propose an improvement to an initializer of all collection >

[swift-evolution] [Pitch] Improve `init(repeating:count)`

2017-08-17 Thread Adrian Zubarev via swift-evolution
This is a small pitch which I will abandon if there is not much appetite for such improvement. ;) I would like to propose an improvement to an initializer of all collection types that provide: init(repeating repeatedValue: Element, count: Int). This change is meant to support reference type