Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-16 Thread Thorsten Seitz via swift-evolution
> Am 12.04.2016 um 01:01 schrieb Yuta Koshizawa : > > Hi. > > Decoding a JSON is just an example. As I replied to Thorsten, we can > think about various cases we want to unwrap multiple optionals at > once. > > This is another example (with the notation `|?` and the postfix > version I proposed

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-11 Thread Yuta Koshizawa via swift-evolution
Hi. Decoding a JSON is just an example. As I replied to Thorsten, we can think about various cases we want to unwrap multiple optionals at once. This is another example (with the notation `|?` and the postfix version I proposed instead of the infix `???`). ``` do { let sum = try Int(aString)|?

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-10 Thread Radosław Pietruszewski via swift-evolution
Just FWIW: > ``` > let foo: Foo? = curry(Foo.init) <^> Int(aString) <*> Int(bString) <*> > Int(cString) > ``` > > But I think it is unreasonable to expect all programmers to understand > and master it. So I want the postfix `???` or `|?`. I agree. But I would also say that deserializing from JSO

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-09 Thread Yuta Koshizawa via swift-evolution
> I only wonder whether you really want to repeat Error() all over, > possibly with `aString` etc. as argument. What I really want is the postfix version of `???` as I wrote in my first post in this thread. > Besides the proposed infix `???`, I also want the postfix one which > throws a `NilError

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-08 Thread Thorsten Seitz via swift-evolution
Am 08.04.2016 um 11:59 schrieb Brent Royal-Gordon : >> I only wonder whether you really want to repeat Error() all over, possibly >> with `aString` etc. as argument. > > `Error()`, no. `SpimsterKitError.invalidWicketField("a"`), yes, because even > if `Int.init(_:)` threw *an* error, it wouldn

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-08 Thread Brent Royal-Gordon via swift-evolution
> I only wonder whether you really want to repeat Error() all over, possibly > with `aString` etc. as argument. `Error()`, no. `SpimsterKitError.invalidWicketField("a"`), yes, because even if `Int.init(_:)` threw *an* error, it wouldn't throw *your* error. -- Brent Royal-Gordon Architechies _

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-08 Thread Thorsten Seitz via swift-evolution
___ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-07 Thread Guillaume Lessard via swift-evolution
A different direction would be to add a non-autoclosure variant to ?? that explicitly takes a closure. public func ??(optional: T?, defaultValue: () throws -> T) rethrows -> T { switch optional { case .Some(let wrapped): return wrapped case .None: return try defaultValue() } } Then, the

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-07 Thread Yuta Koshizawa via swift-evolution
Of course we can implement a library with `throws` by changing those properties to methods. However we can think about similar cases. ``` do { let foo: Foo = try foo( a: Int(aString) ??? Error(), b: Int(bString) ??? Error(), c: Int(cString) ??? Error() ) } catch _ {

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-07 Thread Thorsten Seitz via swift-evolution
___ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-07 Thread Yuta Koshizawa via swift-evolution
> I'd like to see some real-world examples of this before we did anything with > it. The following is my real-world example. ``` // Decodes a JSON with SwiftyJSON do { let person: Person = try Person( firstName: json["firstName"].string ??? Error(), lastName: json["lastName"].string ??

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread David Hart via swift-evolution
I agree with Sean, I ready use guard and don't see much use in a StdLib or operator alternative. Sent from my iPad > On 06 Apr 2016, at 17:00, Sean Heber via swift-evolution > wrote: > > Interesting, but I’m unsure if all of it is significantly better than just > using the guard that is effe

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread John McCall via swift-evolution
> On Apr 6, 2016, at 9:21 AM, Brent Royal-Gordon via swift-evolution > wrote: >>> Interesting, but I’m unsure if all of it is significantly better than just >>> using the guard that is effectively inside of the operator/func that is >>> being proposed: >>> >>> guard let value = Int("NotANumber

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Yuta Koshizawa via swift-evolution
I agree with this and I like the operator approach. Besides the proposed infix `???`, I also want the postfix one which throws a `NilError` (something like `struct NilError: ErrorType {}`). It is useful to handle multiple `nil`s at once when we are not interested in the kind of the error. ``` //

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Howard Lovatt via swift-evolution
Personally I would like Optional to gain `ifNil` (`??` would call `ifNil`) and `ifNilThrow`, both of which have an auto closure argument returning a value and throwing respectively. This would save adding an extra operator and allow chaining to read better than `??` in some circumstances, like when

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Jordan Rose via swift-evolution
I think I'm with Sean on this one. Optionals and throwing don't have enough to do with each other to actually come up with a specific operator or method for this. I can't help but see this as two ideas glued together: - "By this point in my execution I need a non-optional value, otherwise __

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Pyry Jahkola via swift-evolution
>>> Interesting, but I’m unsure if all of it is significantly better than just >>> using the guard that is effectively inside of the operator/func that is >>> being proposed: >>> >>> guard let value = Int("NotANumber") else { throw >>> InitializerError.invalidString } >> >> That is a pretty da

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Haravikk via swift-evolution
I’m inclined to agree with this; the guard statement is fairly clear, though a slightly cleaner construct for throwing would be nice. That said, it isn’t mutually exclusive with the MikeAsh alternative provided, which could still be a nice addition for those that prefer it (though it’s also a fa

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Brent Royal-Gordon via swift-evolution
>> Interesting, but I’m unsure if all of it is significantly better than just >> using the guard that is effectively inside of the operator/func that is >> being proposed: >> >> guard let value = Int("NotANumber") else { throw >> InitializerError.invalidString } >> > > That is a pretty damn c

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Erica Sadun via swift-evolution
> On Apr 6, 2016, at 9:00 AM, Sean Heber wrote: > > Interesting, but I’m unsure if all of it is significantly better than just > using the guard that is effectively inside of the operator/func that is being > proposed: > > guard let value = Int("NotANumber") else { throw > InitializerError.i

Re: [swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Sean Heber via swift-evolution
Interesting, but I’m unsure if all of it is significantly better than just using the guard that is effectively inside of the operator/func that is being proposed: guard let value = Int("NotANumber") else { throw InitializerError.invalidString } It is only a couple of characters longer and alre

[swift-evolution] [Pre-Draft] Nil-coalescing and errors

2016-04-06 Thread Erica Sadun via swift-evolution
Pyry Jahkola and I have been plugging away on the following which is preliminary enough not to qualify as an actual draft. He prefers the Mike Ash approach. I prefer the operator approach. So we have not actually settled on which one we would actually propose despite how I've written this up. I