Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Funcitonal Swift Conference: The Functional Way

11,759 views

Published on

Talk about Functional Swift presented at the Functional Swift Conference http://2014.funswiftconf.com/

Published in: Software, Engineering, Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • High paying Twitter jobs? $25 per hour, start immediately ▲▲▲ http://t.cn/AieXiXbg
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • 1 cup burns 1lb of diabetic fat every 72 hours... ●●● http://scamcb.com/bloodsug/pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Real people just like you are kissing the idea of punching the clock for someone else goodbye, and embracing a new way of living. The internet economy is exploding, and there are literally THOUSANDS of great earnings opportunities available right now, all just one click away. ●●● http://t.cn/AisJWCv6
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Funcitonal Swift Conference: The Functional Way

  1. THE FUNCTIONAL WAY @NATASHATHEROBOT
  2. "functional programming is a programming paradigm... that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data." Wikipedia
  3. "A mathematical function is a function that when you give it the same argument, it will give you the same result" - Edx FP101x
  4. ▸ computation as the evaluation of mathematical functions ▸ avoid changing state ▸ avoid mutable data
  5. NO SIDE EFFECTS
  6. let numbers = Array(1...10) var total = 0 func addNumbers() { for number in numbers { total += number } }
  7. addNumbers() total // 55 addNumbers() total // 110 addNumbers() total // 165
  8. let myNumbers = Array(1...10) var total = addNumbers(myNumbers) func addNumbers(numbers: [Int]) -> Int { // can also be written shorthand as // numbers.reduce(0,+) return numbers.reduce(0) { (sum, number) in sum + number } }
  9. total = addNumbers(myNumbers) // 55 total = addNumbers(myNumbers) // 55 total = addNumbers(myNumbers) // 55
  10. import Foundation class Gift { let recipient: String let item: String let budget: NSDecimalNumber let status: Status enum Status: String { case Purchased = "Purchased" case Wrapped = "Wrapped" case Delivered = "Delivered" } init(recipient: String, item: String, budget: NSDecimalNumber, status: Status) { self.recipient = recipient self.item = item self.budget = budget self.status = status } }
  11. extension Gift { func todo() -> String { switch status { case .Purchased: return "Wrap it!" case .Wrapped: return "Mail it!" case .Delivered: return "Relax and drink some eggnog :)" } } }
  12. extension Gift { func todo(fromStatus status: Status) -> String { switch status { case .Purchased: return "Wrap it!" case .Wrapped: return "Mail it!" case .Delivered: return "Relax and drink some eggnog :)" } } }
  13. class GiftTests: XCTestCase { func testTodo_Purchased() { let gift = Gift( recipient: "My Cousin Julie, item: "GoldieBlox", budget: NSDecimalNumber(double: 20.00), status: .Purchased) XCTAssertEqual(gift.todo(), "Wrap it!") } func testTodo_Wrapped() { let gift = Gift( recipient: "My Cousin Julie", item: "GoldieBlox", budget: NSDecimalNumber(double: 20.00), status: .Wrapped) XCTAssertEqual(gift.todo(), "Mail it!") } func testTodo_Delivered() { let gift = Gift( recipient: "My Cousin Julie", item: "GoldieBlox", budget: NSDecimalNumber(double: 20.00), status: .Delivered) XCTAssertEqual(gift.todo(), "Relax and drink some eggnog :)") } }
  14. import XCTest class GiftTests: XCTestCase { let gift = Gift( recipient: "My Cousin Tommy", item: "Choo Choo Train", budget: NSDecimalNumber(double: 20.00), status: .Purchased) func testTodo_Purchased() { XCTAssertEqual(gift.todo(fromStatus: .Purchased), "Wrap it!") } func testTodo_Wrapped() { XCTAssertEqual(gift.todo(fromStatus: .Wrapped), "Mail it!") } func testTodo_Delivered() { XCTAssertEqual(gift.todo(fromStatus: .Delivered), "Relax and drink some eggnog :)") } }
  15. import XCTest class GiftTests: XCTestCase { func testTodo_Purchased() { XCTAssertEqual(Gift.todo(fromStatus: .Purchased), "Wrap it!") } func testTodo_Wrapped() { XCTAssertEqual(Gift.todo(fromStatus: .Wrapped), "Mail it!") } func testTodo_Delivered() { XCTAssertEqual(Gift.todo(fromStatus: .Delivered), "Relax and drink some eggnog :)") } }
  16. VALUE TYPES
  17. "Almost all types in Swift are value types, including arrays, dictionaries, numbers, booleans, tuples, and enums. Classes are the exception rather than the rule." - Functional Swift Book
  18. NSError *err = nil; CGFloat result = [MYArithmetic divide:2.5 by:3.0 error:&err]; if (err) { NSLog(@"%@", err) } else { [MYArithmetic doSomethingWithResult:result] } @nomothetis
  19. enum Result { case Success(AnyObject) case Failure(NSError) } @nomothetis
  20. let result = MYArithmetic.divide(2.5, by:3) switch result { case Success(let quotient): doSomethingWithResult(quotient) case Failure(let error): handleError(error) } @nomothetis
  21. http://nomothetis.svbtle.com/error-handling-in-swift
  22. CURRYING
  23. func add(x: Int, y: Int) -> Int { return x + y } add(2, 3) // 5
  24. func add(x: Int) -> Int -> Int { return { y in return x + y } } let partialAdd = add(2) // let addFunc: (Int -> Int) let sum = partialAdd(3) // 5 let arr = [1,2,3] let incrementBy2 = arr.map(partialAdd) // [3,4,5] add(6)(4) // 10
  25. func add(#x: Int)(y: Int) -> Int { return x + y } add(x: 2)(y: 3) // 5
  26. struct Logger { /// Level of log message to aid in the filtering of logs enum Level: Int, Printable { /// Messages intended only for debug mode case Debug = 3 /// Messages intended to warn of potential errors case Warn = 2 /// Critical error messages case Error = 1 /// Log level to turn off all logging case None = 0 var description: String { switch(self) { case .Debug: return "Debug" case .Warn: return "Warning" case .Error: return "Error" case .None: return "" } } } } @drewag
  27. extension Logger { /// What is the max level to be logged /// /// Any logs under the given log level will be ignored static var logLevel: Level = .Warn /// Log a message to the console static func log (#level: Level) (name: String) (message: String) -> String { if level.rawValue <= Logger.logLevel.rawValue { return "(level.description): (name) - (message)" } return "" } } @drewag
  28. Logger.log(level: .Debug)(name: "MyFunction")(message: "Is this being called?") // Debug: MyFunction - Is this being called?
  29. extension Logger { /// Logger for debug messages static var debug = Logger.log(level: .Debug) // static var debug: (name: String) -> (message: String) -> String /// Logger for warnings static var warn = Logger.log(level: .Warn) /// Logger for errors static var error = Logger.log(level: .Error) } @drewag
  30. Logger.logLevel = .Debug func myFunctionToDebug() { var x = 5 // do something to x Logger.debug(name: "myFunctionToDebug")(message: "x: (x)") } myFunctionToDebug() // Prints: "Debug: myFunctionToDebug - x: 10" @drewag
  31. func myFunctionToDebug() { var x = 5 var y = 3 // do something to x // do something to y let debugMyFunction = Logger.debug(name: "myFunctionToDebug") debugMyFunction(message: "x: (x)") debugMyFunction(message: "y: (y)") } myFunctionToDebug() // Prints: "Debug: myFunctionToDebug - x: 10" // Prints: "Debug: myFunctionToDebug - y: 13"
  32. http://drewag.me/posts/practical-use-for-curried-functions-in-swift
  33. TYPE-DRIVEN DESIGN
  34. func credits(account: Account) -> Int { // ask data source for account credits return credits } @FunctionalSwift
  35. typealias Credits = Int func credits(account: Account) -> Credits { // ask data source for amount of credits return amount } @FunctionalSwift
  36. "One important lesson I've learned is that designing the right types for your problem is a great way to help the compiler debug your program." - @wouterswierstra
  37. struct Credits { let amount: Int } func credits(account: Account) -> Credits { // ask data source for amount of credits return Credits(amount: amount) } @FunctionalSwift
  38. let myCredits = credits(myAccount) myCredits + 1 // ERROR // Cannot invoke '+' with an argument of type // '(Credit, IntegerLiteralConvertable)'
  39. http://www.objc.io/snippets/8.html http://www.swiftcast.tv/articles/the-design-of-types
  40. RESOURCES ▸ Functional Swift Book ▸ Edx FP101x ▸ Functional Snippets ▸ An Introduction to Haskell - Skills Matter ▸ swiftnews.curated.co
  41. QUESTIONS? @NATASHATHEROBOT

×