SlideShare a Scribd company logo
1 of 28
Download to read offline
What’s to come with
swift generics
Generics1
struct Array<Element> {
/* Implementation */
}
struct Array<Element> {
/* Implementation */
}
struct Optional<Wrapped> {
/* Implementation */
}
// Here T can be any type we want
func swapTwoValues<T>(_ a: inout T, _ b: inout T) {
let temporaryA = a
a = b
b = temporaryA
}
// Here T can be any type we want
func swapTwoValues<T>(_ a: inout T, _ b: inout T) {
let temporaryA = a
a = b
b = temporaryA
}
// Here T has to conform to Comparable
func compare<T: Comparable>(a: T, b: T) -> Bool {
return a > b
}
Type-level VS Value-level abstraction2
Type-level abstraction
// Any type conforming to Comparable can be used as parameter
func compare<T: Comparable>(a: T, b: T) -> Bool {
return a > b
}
Type-level abstraction
// Any type conforming to Comparable can be used as parameter
func compare<T: Comparable>(a: T, b: T) -> Bool {
return a > b
}
Value-level abstraction
// Any value which has a conforming type to Protocol
// can be stored in the variable
var variable: Protocol
SE-0244 Opaque result type3
Type-level abstraction for function returns
func foo<T: Constraints>() -> T {
// Implementation
}
Type-level abstraction for function returns
func foo<T: Constraints>() -> T {
// Implementation
}
func foo() -> Constraints {
// Implementation
}
Type-level abstraction for function returns
func foo<T: Constraints>() -> T {
// Implementation
}
func foo() -> Constraints {
// Implementation
}
func foo() -> some Constraints {
// Implementation
}
Why letting the callee decide of the type ?
Why letting the callee decide of the type ?
protocol Shape {
func draw(to: Surface)
func collides<Other: Shape>(with: Other) -> Bool
}
struct Rectangle: Shape { /* Implementation */ }
struct Circle: Shape { /* Implementation */ }
struct Union<A: Shape, B: Shape>: Shape {
var a: A, b: B
/* Implementation */
}
struct Intersect<A: Shape, B: Shape>: Shape {
var a: A, b: B
/* Implementation */
}
struct Transformed<S: Shape>: Shape {
var shape: S
var transform: Matrix3x3
/* Implementation */
}
Why letting the callee decide of the type ?
protocol GameObject {
// The shape of the object
associatedtype Shape: Shapes.Shape
var shape: Shape { get }
}
Why letting the callee decide of the type ?
protocol GameObject {
// The shape of the object
associatedtype Shape: Shapes.Shape
var shape: Shape { get }
}
struct EightPointedStar: GameObject {
var shape: Union<Rectangle, Transformed<Rectangle>> {
return Union(Rectangle(), Transformed(shape: Rectangle(), transform: .fortyFiveDegrees)
}
}
Why letting the callee decide of the type ?
protocol GameObject {
// The shape of the object
associatedtype Shape: Shapes.Shape
var shape: Shape { get }
}
struct EightPointedStar: GameObject {
var shape: Union<Transformed<Rectangle>, Rectangle> {
return Union(Transformed(shape: Rectangle(), transform: .fortyFiveDegrees), Rectangle())
}
}
Why letting the callee decide of the type ?
protocol GameObject {
// The shape of the object
associatedtype Shape: Shapes.Shape
var shape: Shape { get }
}
struct EightPointedStar: GameObject {
var shape: some Shape {
return Union(Transformed(shape: Rectangle(), transform: .fortyFiveDegrees), Rectangle())
}
}
Key informations about opaque result types
Key informations about opaque result types
Opaque result type is different from existential type
Key informations about opaque result types
Opaque result type is different from existential type
The compiler knows what is the underlying type
Key informations about opaque result types
Opaque result type is different from existential type
The compiler knows what is the underlying type
Opaque result types cannot be wrapped
What is to come?4
// Any value which has a conforming type to Protocol
// can be stored in the variable
var variable: any Protocol
Clarifying existential types
func foo<T: Collection, U: Collection>(x: T, y: U) -> some Collection
func foo(x: Collection, y: Collection) -> some Collection
Improving the notation for generics
func concatenate<T>(
a: some Collection<.Element == T>,
b: some Collection<.Element == T>
) -> some Collection<.Element == T>
Generalizing some syntax to arguments and returns
Thank you
CONTACT
Denis POIFOL
Software engineer
+33 6 58 90 85 54
denis.poifol@fabernovel.com

More Related Content

What's hot

Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpprajshreemuthiah
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overviewgourav kottawar
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Kamlesh Makvana
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
Effective refactoring
Effective refactoringEffective refactoring
Effective refactoringArnon Axelrod
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingabhay singh
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3Chris Farrell
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04IIUM
 
Templates presentation
Templates presentationTemplates presentation
Templates presentationmalaybpramanik
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETDmitri Nesteruk
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract classAmit Trivedi
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading Charndeep Sekhon
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 

What's hot (20)

Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
classes & objects in cpp overview
classes & objects in cpp overviewclasses & objects in cpp overview
classes & objects in cpp overview
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Scala functions
Scala functionsScala functions
Scala functions
 
Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function Virtual function in C++ Pure Virtual Function
Virtual function in C++ Pure Virtual Function
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
Effective refactoring
Effective refactoringEffective refactoring
Effective refactoring
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Learning php 7
Learning php 7Learning php 7
Learning php 7
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
 
Templates presentation
Templates presentationTemplates presentation
Templates presentation
 
C language presentation
C language presentationC language presentation
C language presentation
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
 
C++ quik notes
C++ quik notesC++ quik notes
C++ quik notes
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Presentation on overloading
Presentation on overloading Presentation on overloading
Presentation on overloading
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 

Similar to Whats to come with swift generics

The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta ProgrammingReggie Meisler
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScriptAleš Najmann
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative FunctorsDavid Galichet
 
Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Yaksh Jethva
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with SwiftFatih Nayebi, Ph.D.
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality codeJack Fox
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11Uilian Ries
 
Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Emmanuel Nhan
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义yiditushe
 

Similar to Whats to come with swift generics (20)

Introduction to Swift
Introduction to SwiftIntroduction to Swift
Introduction to Swift
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
Practical Meta Programming
Practical Meta ProgrammingPractical Meta Programming
Practical Meta Programming
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 
All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Function C++
Function C++ Function C++
Function C++
 
2.dynamic
2.dynamic2.dynamic
2.dynamic
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
Java 8 Feature Preview
Java 8 Feature PreviewJava 8 Feature Preview
Java 8 Feature Preview
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
Writing DSL with Applicative Functors
Writing DSL with Applicative FunctorsWriting DSL with Applicative Functors
Writing DSL with Applicative Functors
 
Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)Operator_Overloaing_Type_Conversion_OOPC(C++)
Operator_Overloaing_Type_Conversion_OOPC(C++)
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Functional programming for production quality code
Functional programming for production quality codeFunctional programming for production quality code
Functional programming for production quality code
 
Bw14
Bw14Bw14
Bw14
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
 
Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]Functional programming in kotlin with Arrow [Sunnytech 2018]
Functional programming in kotlin with Arrow [Sunnytech 2018]
 
李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义李建忠、侯捷设计模式讲义
李建忠、侯捷设计模式讲义
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Whats to come with swift generics

  • 1. What’s to come with swift generics
  • 3. struct Array<Element> { /* Implementation */ }
  • 4. struct Array<Element> { /* Implementation */ } struct Optional<Wrapped> { /* Implementation */ }
  • 5. // Here T can be any type we want func swapTwoValues<T>(_ a: inout T, _ b: inout T) { let temporaryA = a a = b b = temporaryA }
  • 6. // Here T can be any type we want func swapTwoValues<T>(_ a: inout T, _ b: inout T) { let temporaryA = a a = b b = temporaryA } // Here T has to conform to Comparable func compare<T: Comparable>(a: T, b: T) -> Bool { return a > b }
  • 8. Type-level abstraction // Any type conforming to Comparable can be used as parameter func compare<T: Comparable>(a: T, b: T) -> Bool { return a > b }
  • 9. Type-level abstraction // Any type conforming to Comparable can be used as parameter func compare<T: Comparable>(a: T, b: T) -> Bool { return a > b } Value-level abstraction // Any value which has a conforming type to Protocol // can be stored in the variable var variable: Protocol
  • 11. Type-level abstraction for function returns func foo<T: Constraints>() -> T { // Implementation }
  • 12. Type-level abstraction for function returns func foo<T: Constraints>() -> T { // Implementation } func foo() -> Constraints { // Implementation }
  • 13. Type-level abstraction for function returns func foo<T: Constraints>() -> T { // Implementation } func foo() -> Constraints { // Implementation } func foo() -> some Constraints { // Implementation }
  • 14. Why letting the callee decide of the type ?
  • 15. Why letting the callee decide of the type ? protocol Shape { func draw(to: Surface) func collides<Other: Shape>(with: Other) -> Bool } struct Rectangle: Shape { /* Implementation */ } struct Circle: Shape { /* Implementation */ } struct Union<A: Shape, B: Shape>: Shape { var a: A, b: B /* Implementation */ } struct Intersect<A: Shape, B: Shape>: Shape { var a: A, b: B /* Implementation */ } struct Transformed<S: Shape>: Shape { var shape: S var transform: Matrix3x3 /* Implementation */ }
  • 16. Why letting the callee decide of the type ? protocol GameObject { // The shape of the object associatedtype Shape: Shapes.Shape var shape: Shape { get } }
  • 17. Why letting the callee decide of the type ? protocol GameObject { // The shape of the object associatedtype Shape: Shapes.Shape var shape: Shape { get } } struct EightPointedStar: GameObject { var shape: Union<Rectangle, Transformed<Rectangle>> { return Union(Rectangle(), Transformed(shape: Rectangle(), transform: .fortyFiveDegrees) } }
  • 18. Why letting the callee decide of the type ? protocol GameObject { // The shape of the object associatedtype Shape: Shapes.Shape var shape: Shape { get } } struct EightPointedStar: GameObject { var shape: Union<Transformed<Rectangle>, Rectangle> { return Union(Transformed(shape: Rectangle(), transform: .fortyFiveDegrees), Rectangle()) } }
  • 19. Why letting the callee decide of the type ? protocol GameObject { // The shape of the object associatedtype Shape: Shapes.Shape var shape: Shape { get } } struct EightPointedStar: GameObject { var shape: some Shape { return Union(Transformed(shape: Rectangle(), transform: .fortyFiveDegrees), Rectangle()) } }
  • 20. Key informations about opaque result types
  • 21. Key informations about opaque result types Opaque result type is different from existential type
  • 22. Key informations about opaque result types Opaque result type is different from existential type The compiler knows what is the underlying type
  • 23. Key informations about opaque result types Opaque result type is different from existential type The compiler knows what is the underlying type Opaque result types cannot be wrapped
  • 24. What is to come?4
  • 25. // Any value which has a conforming type to Protocol // can be stored in the variable var variable: any Protocol Clarifying existential types
  • 26. func foo<T: Collection, U: Collection>(x: T, y: U) -> some Collection func foo(x: Collection, y: Collection) -> some Collection Improving the notation for generics
  • 27. func concatenate<T>( a: some Collection<.Element == T>, b: some Collection<.Element == T> ) -> some Collection<.Element == T> Generalizing some syntax to arguments and returns
  • 28. Thank you CONTACT Denis POIFOL Software engineer +33 6 58 90 85 54 denis.poifol@fabernovel.com