Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SwiftのNeverとボトム型 / Never as a Bottom Type

Hiron
April 14, 2019

SwiftのNeverとボトム型 / Never as a Bottom Type

第7回カンファレンス動画鑑賞会で供養したLTの資料です。

Hiron

April 14, 2019
Tweet

More Decks by Hiron

Other Decks in Programming

Transcript

  1. Case 2 let data: [String: String] = ... guard let

    name = data["name"] else { throw ParseError.missing("name") } speaker.name = name guard let icon = data["icon"] else { throw ParseError.missing("icon") } speaker.icon = icon
  2. Case 2 let data: [String: String] = ... speaker.name =

    data["name"] ?? try missing("name") speaker.icon = data["icon"] ?? try missing("icon") func missing(_ key: String) throws -> Never { throw ParseError.missing(key) }
  3. Case 2+ let data: [String: String] = ... speaker.name =

    data["name"] ?? throw ParseError.missing("name") speaker.icon = data["icon"] ?? throw ParseError.missing("icon") ͞Βʹthrow͕NeverΛฦࣜ͢ͳΒ
  4. Case 3 enum Result<Value, Error: Swift.Error> { case success(Value) case

    failure(Error) } func foo() -> Result<String, Never> { ... } foo͸ࣦഊ͠ͳ͍
  5. Protocol • ΠϯελϯεϓϩύςΟ (var) • Πϯελϯεϝιου (func) • ܕϓϩύςΟ (static

    var) • ܕϝιου (static func) • ΠχγϟϥΠβ (init) Πϯελϯεʹର͢Δ
 ੍໿Ͱ͸ͳ͍
  6. Never as a Bottom Type • SE-0215 - Conform Never

    to Equatable and Hashable
 https://forums.swift.org/t/se-0215-conform-never-to-equatable-and-hashable/13586 • SE-0102: Remove @noreturn attribute and introduce an empty Never type
 https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom- type.md • [Pitch] Never as a bottom type
 https://forums.swift.org/t/pitch-never-as-a-bottom-type/5920
  7. Case 2 (Kotlin) val data: Map<String, String> = ... speaker.name

    = data["name"] ?: throw MissingException("name") speaker.icon = data["icon"] ?: throw MissingException("icon") throw͸NothingΛฦࣜ͢