Skip to content

Instantly share code, notes, and snippets.

@hanawat
Last active February 4, 2017 07:26
Show Gist options
  • Save hanawat/ef3b443040b54988b3de23e4f244782e to your computer and use it in GitHub Desktop.
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
struct FooFooFooFooFoo {
static func bar() { }
func baz() {
FooFooFooFooFoo.bar() // Before
type(of: self).bar() // Before
Self.bar() // After
}
}
func sortedArrays<T: Comparable>(arrays: [[T]]) -> [T] {
// Error: `map` expects [T] -> [T], but
// `Array.sorted` has type ([T]) -> () -> [T]
return arrays.map(Array.sorted)
}
public func ==<Element : Equatable>(lhs: ContiguousArray<Element>, rhs: ContiguousArray<Element>) -> Bool
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
#if canImport(UIKit)
// UIKit-based code
#elseif canImport(Cocoa)
// OSX code
#elseif
// Workaround/text, whatever
#endif
let foo: Int8 = 1
let bar = 2
// error: binary operator '<<' cannot be applied
// to operands of type 'Int8' and 'Int'
let baz = foo << bar
+--------------+ +-------------+
+------>+ Arithmetic | | Comparable |
| | (+,-,*,/) | | (==,<,>,...)|
| +-------------++ +---+---------+
| ^ ^
+-------+------------+ | |
| SignedArithmetic | +-+-------+------+
| (unary -) | | BinaryInteger |
+------+-------------+ | (words,%,...) |
^ ++---+-----+-----+
| +-----------^ ^ ^-----------+
| | | |
+------+---------++ +---------+-------------+ ++------------------+
| SignedInteger | | FixedWidthInteger | | UnsignedInteger |
| | | (bitwise,overflow,...)| | |
+---------------+-+ +-+-----------------+---+ ++------------------+
^ ^ ^ ^
| | | |
| | | |
++--------+-+ +-+-------+-+
|Int family |-+ |UInt family|-+
+-----------+ | +-----------+ |
+-----------+ +-----------+
protocol Foo {
associatedtype Bar: Sequence where Bar.Iterator.Element == Int
func baz() -> Bar
}
protocol Foo : Sequence where Iterator.Element == Int { ... }
// error: Use of undefined associated type 'Counter'
protocol Foo: Sequence where Counter: Bar {
associatedtype Counter
}
protocol Foo: Sequence {
associatedtype Counter: Bar
}
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