Last active
February 4, 2017 07:26
-
-
Save hanawat/ef3b443040b54988b3de23e4f244782e to your computer and use it in GitHub Desktop.
Swift EvolutionのAcceptedステータスまとめ (2017.1.27) - Protocol-oriented integers, Permit where clauses to constrain associated types, ...etc ref: http://qiita.com/hanawat/items/6e76d958a22b6e77d6ea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FooFooFooFooFoo { | |
static func bar() { } | |
func baz() { | |
FooFooFooFooFoo.bar() // Before | |
type(of: self).bar() // Before | |
Self.bar() // After | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sortedArrays<T: Comparable>(arrays: [[T]]) -> [T] { | |
// Error: `map` expects [T] -> [T], but | |
// `Array.sorted` has type ([T]) -> () -> [T] | |
return arrays.map(Array.sorted) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func ==<Element : Equatable>(lhs: ContiguousArray<Element>, rhs: ContiguousArray<Element>) -> Bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
let x: Int | |
func bar(y: Int) -> Int { | |
return x + y | |
} | |
} | |
let f = Foo.bar // (Foo) -> (Int) -> Int | |
let g = f(Foo(x: 2))(3) // Before | |
let g = f(Foo(x: 2), 3) // After |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if canImport(UIKit) | |
// UIKit-based code | |
#elseif canImport(Cocoa) | |
// OSX code | |
#elseif | |
// Workaround/text, whatever | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let foo: Int8 = 1 | |
let bar = 2 | |
// error: binary operator '<<' cannot be applied | |
// to operands of type 'Int8' and 'Int' | |
let baz = foo << bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+--------------+ +-------------+ | |
+------>+ Arithmetic | | Comparable | | |
| | (+,-,*,/) | | (==,<,>,...)| | |
| +-------------++ +---+---------+ | |
| ^ ^ | |
+-------+------------+ | | | |
| SignedArithmetic | +-+-------+------+ | |
| (unary -) | | BinaryInteger | | |
+------+-------------+ | (words,%,...) | | |
^ ++---+-----+-----+ | |
| +-----------^ ^ ^-----------+ | |
| | | | | |
+------+---------++ +---------+-------------+ ++------------------+ | |
| SignedInteger | | FixedWidthInteger | | UnsignedInteger | | |
| | | (bitwise,overflow,...)| | | | |
+---------------+-+ +-+-----------------+---+ ++------------------+ | |
^ ^ ^ ^ | |
| | | | | |
| | | | | |
++--------+-+ +-+-------+-+ | |
|Int family |-+ |UInt family|-+ | |
+-----------+ | +-----------+ | | |
+-----------+ +-----------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Foo { | |
associatedtype Bar: Sequence where Bar.Iterator.Element == Int | |
func baz() -> Bar | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Foo : Sequence where Iterator.Element == Int { ... } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// error: Use of undefined associated type 'Counter' | |
protocol Foo: Sequence where Counter: Bar { | |
associatedtype Counter | |
} | |
protocol Foo: Sequence { | |
associatedtype Counter: Bar | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array: Equatable where Element: Equatable { | |
static func ==(lhs: Array<Element>, rhs: Array<Element>) -> Bool { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment