> On 25 May 2016, at 16:51, Jeremy Pereira
> wrote:
>> On 24 May 2016, at 12:33, Haravikk via swift-evolution
>> wrote:
>>> On 23 May 2016, at 20:19, Dany St-Amant via swift-evolution
>>> wrote:
>>>
>>>
> On 24 May 2016, at 12:33, Haravikk via swift-evolution
> wrote:
>
>
>> On 23 May 2016, at 20:19, Dany St-Amant via swift-evolution
>> wrote:
>>
>> Challenge accepted… Removed the if/else if, at the cost of double function
>> call to
Ok, how about this? The compiler currently crashes when compiling this, but
IMHO it is (or should be) valid code.
enum IntegerSign: NumberType {
case Negative = -1
case Zero = 0
case Positive = 1
var signum: NumberType {
return self.rawValue
}
}
The RawValue is an Int, but signum is a T, which I thought was the point. I
tried saying `T: IntegerLiteralConvertible`, and making RawValue = T, but the
playground didn’t like that. Maybe with some of Swift 3’s generic enhancements,
it could be that simple.
In any case, it sounds like this
Yes, but here, the rawValue is Int - in my code, the rawValue is NumberType,
which IMHO makes more sense...
> On May 24, 2016, at 7:36 AM, David Sweeris wrote:
>
> Sorry, I misspoke. I just meant define it like this:
> public enum IntegerSign : Int {
> case Negative =
Sorry, I misspoke. I just meant define it like this:
public enum IntegerSign : Int {
case Negative = -1
case Zero = 0
case Positive = 1
public var signum: T {
return T(self.rawValue.toIntMax())
}
}
Although, come to think of it, I’m not sure if that’s an exact drop-in
Sure, that's a good idea, though I'd personally use the signum var, since using
rawValue seems like a bit of an abuse of the fact the enum is defined this way
and doesn't help readability of the code:
enum IntegerSign: RawRepresentable {
case Negative
case Zero
case Positive
Can we make it RawRepresentable? That way signum can just return self.rawValue
Sent from my iPhone
> On May 23, 2016, at 06:05, Charlie Monroe via swift-evolution
> wrote:
>
> The clean way would be to make it an enum with var signum that would return
> -1, 0, 1:
>
> Le 22 mai 2016 à 03:07, Adam Nemecek via swift-evolution
> a écrit :
>
> Howdy,
> I think that the SignedNumberType should implement a method called sign that
> will return -1 for negative numbers, 0 for 0 and 1 for positive numbers. This
> is similar to the
The clean way would be to make it an enum with var signum that would return -1,
0, 1:
enum IntegerSign {
case Negative
case Zero
case Positive
var signum: NumberType {
switch self {
case .Negative:
return -1 as NumberType
case .Zero:
Whoops didn’t check that your example worked as well :D
--
Adrian Zubarev
Sent with Airmail
Am 22. Mai 2016 bei 10:27:17, Adrian Zubarev (adrian.zuba...@devandartist.com)
schrieb:
This should do the trick:
extension SignedNumberType {
var sign: Self {
if self
Howdy,
I think that the SignedNumberType should implement a method called sign
that will return -1 for negative numbers, 0 for 0 and 1 for positive
numbers. This is similar to the signum method in e.g. Java and similarly
called methods in other languages.
The implementation is fairly straight
12 matches
Mail list logo