Publicité
Publicité

Contenu connexe

Publicité

Plus de Tomohiro Kumagai(20)

Publicité

_Function Builders in Swift #love_swift

  1. func serialization() -> String { var serialized = "" serialized += String(SerializedValue(turn: turn)) serialized += "n" serialized += String(SerializedValue(board: board)) serialized += "n" return serialized }
  2. @Serialization func serialization() -> String { turn board }
  3. @_functionBuilder enum Sample { // }
  4. @Sample func execute() -> Component { // DSL } init(@Sample body:()->Component) { // DSL }
  5. 1. buildExpression(_: Expression) -> Component 2. buildBlock(_: Component ...) -> Component 3. buildDo(_: Component ...) -> Component
  6. buildEither(first: Component) -> Component buildEither(second: Component) -> Component
  7. buildFunction(_: Components...) -> Return buildOptional(_: Component?) -> Component
  8. static func buildBlock( _ a: Component, _ b: Component) -> Component { }
  9. static func buildBlock(_ a: Int, _ b: String, _ c: Bool) -> Component { }
  10. static func buildBlock(_ components: Component...) -> Component { }
  11. static func buildBlock(_ a: Int, _: Void) -> Component { }
  12. static func buildExpression() -> Component { }
  13. static func buildExpression(_ expression: Expression) -> Component { }
  14. static func buildExpression(_: Void) -> Component { }
  15. static func buildExpression(_: Never) -> Component { }
  16. static func buildExpression(_: Never) -> Component { } static func buildExpression<T>(_ expression: T) -> T { return expression }
  17. Do
  18. static func buildDo(_ component: Component) -> Component { }
  19. If
  20. if … { ① } else { ② } BLOCK 2nd1st
  21. if … { ① } else if { ② } else { ③ } 2nd1st BLOCK 2nd1st
  22. 2nd1st if … { ① } else if … { ② } else if … { ③ } else { ④ } BLOCK 2nd1st 2nd1st
  23. if … { ① } else if … { ② } else if … { ③ } else if … { ④ } else { ⑤ BLOCK 1st 2nd 1st 2nd 1st 2nd 1st 2nd
  24. BLOCK 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd
  25. BLOCK 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd
  26. BLOCK 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd 1st 2nd
  27. BLOCK 1st 2n 1st 2nd 1st 2n 1st 2n 1st 2n 1st 2n 1st 2n 1st 2nd
  28. BLOCK 1st 2n 1st 2nd 1st 2n 1st 2n 1st 2n 1st 2n 1st 2n 1st 2nd 2nd1st
  29. BLOCK 1st 2n 1st 2nd 1st 2n 1st 2n 1st 2n 1st 2n 1st 2n 1st 2nd 2nd1st 1st 2n
  30. if … { ① } else { if … { ② } else { ③ } } BLOCK 2nd1st 2nd1st BLOCK
  31. Build Block Build ExpressionBuild Expression Build DoBuild Do Build Function Build If Build Optional Build Block Build DoBuild Either Build Block
Publicité