[swift-evolution] Optional Argument Chaining

2017-12-11 Thread Jared Khan via swift-evolution
Hi all, I'd like to propose a syntax addition that acts to ease some things that I believe should fall under the umbrella of 'optional chaining'. Optional chaining allows us to access the properties of an optional value and return nil if any link in that chain breaks. I propose we introduce

Re: [swift-evolution] [Pitch] Generalized supertype constraints

2017-12-11 Thread Magnus Ahltorp via swift-evolution
Mutation is more or less modeled as reassignment in Swift, there is no difference between a variable that can be mutated and one that can be reassigned (right?). There are however differences between inout's real behaviour and what some might expect; some might expect that it is modified at

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Charles Augustine via swift-evolution
I don’t think that solves the same thing. The problem is I read it is to allow some sort of short hand to be able to pass optional types as parameters into methods / initializers that do not take optional types. The result of that method / initializer being nil if any of said parameters were

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Magnus Ahltorp via swift-evolution
> 12 Dec. 2017 01:30 Jared Khan via swift-evolution > wrote: > > I'd like to propose a syntax addition that acts to ease some things that I > believe should fall under the umbrella of 'optional chaining'. Optional > chaining allows us to access the properties of an

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread C. Keith Ray via swift-evolution
You can create a binary operator that tests the left-hand operand for nil, and passes the unwrapped value to the right-hand operand (a function taking one value), this operator can be made left-associative to allow chaining. let m = String(contentsOfFile: "README.md") ??? Markdown where ??? is

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Jared Khan via swift-evolution
1. Correct 2. It felt natural to me. It’s analogous to the existing optional chaining scenarios and composes nicely. I think it’s about as understandable as existing chaining, a newbie would have to look it up to discover its meaning. What are your thoughts on this particular syntax (ignoring

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Matthew Johnson via swift-evolution
It’s worth mentioning that the problem this thread is discussing can be generalized to idioms / applicative. The specific case here is for Optional but many other types could benefit from an elegant syntactic solution to this problem. It might be worth exploring a more general solution.

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Xiaodi Wu via swift-evolution
This topic has been discussed at least two and maybe more times in the past. It’s hard for me to post links at the moment, but it should be possible to find on Google. One major challenge to this idea, for which no satisfactory answer has been achieved after all these years, is the following

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Magnus Ahltorp via swift-evolution
> 12 Dec. 2017 02:58 Jared Khan wrote: > > 2. It felt natural to me. It’s analogous to the existing optional chaining > scenarios and composes nicely. I think it’s about as understandable as > existing chaining, a newbie would have to look it up to discover its meaning. >

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Adrian Zubarev via swift-evolution
This is an interesting example but I think the solution might be simple if we try to desugar it. // example f(g()?, h()?, i(), j()?)? // desugared let/var someF: SomeType? if let someG = g(), let someH = h(), let someJ = j() { someF = f(someG, someH, i(), someJ) } else { someF = nil }

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Jared Khan via swift-evolution
I missed the previous threads! I’ve found one of the relevant threads here: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024201.html Thanks for this important point. If you were to

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Jared Khan via swift-evolution
I missed the previous threads! I’ve found one of the relevant threads here: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024201.html Thanks for this important point. If you were to

[swift-evolution] Proposal and Timeline for Discourse Transition

2017-12-11 Thread Nicole Jacque via swift-evolution
Hi All- Below is a summary proposal for our move to Discourse. Please note, that unless there are any serious objections, we’d like to do this transition over the next weekend, so please communicate any issues that you may see as soon as possible. Please file issues/comments/requests at

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Slava Pestov via swift-evolution
> On Dec 11, 2017, at 2:41 PM, Jared Khan via swift-evolution > wrote: > > I missed the previous threads! I’ve found one of the relevant threads here: > https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160711/024201.html > >

Re: [swift-evolution] Optional Argument Chaining

2017-12-11 Thread Félix Cloutier via swift-evolution
You talk about flatMap without giving an example. The readme isn't that bad with it, IMO: if let readme = String(contentsOfFile: "README.md").flatMap(Markdown) { // use contents here } That doesn't work when you need multiple optional parameters. In my own experience, that hasn't been

Re: [swift-evolution] Proposal and Timeline for Discourse Transition

2017-12-11 Thread Ben Rimmington via swift-evolution
When claiming a staged account, can the username be changed? e.g. Having the same "@username" on GitHub and Swift Forums. Will people with multiple accounts be able to merge them? Names with non-Latin characters are not imported correctly:

[swift-evolution] constant var

2017-12-11 Thread Inder Kumar Rathore . via swift-evolution
Hi All, Today I was writing code and faced a situation where I need to make a instance variable a const i.e. it shouldn't accept new values from anywhere but the problem is that I want it's content to be mutable. e.g. class MyClass { var myDict = [String : String]() } I want above variable

Re: [swift-evolution] Proposal and Timeline for Discourse Transition

2017-12-11 Thread Ben Rimmington via swift-evolution
[Forum] merging multiple staged accounts [Forum] importing names with non-Latin characters -- Ben > On 12 Dec 2017, at 06:41, Ben Rimmington wrote: > > When claiming a staged account, can the username be changed? >

Re: [swift-evolution] constant var

2017-12-11 Thread Rafael Guerreiro via swift-evolution
You actually need a class to wrap the dictionary. That’s because dictionaries are struct, with copy-on-write. With a class, you’ll be able to have it mutable, in a let declaration. On Mon, Dec 11, 2017 at 11:34 PM Inder Kumar Rathore . via swift-evolution < swift-evolution@swift.org> wrote: > Hi