ぜのぜ

しりとりしようぜのぜのぜのぜ

113日目

日記

今日は金曜日ですが今週末も何もせずに過ごすのでしょうか

今日書いたコード

func some(_ closure: (() -> ())?) {
    closure?()
}

some {
    print("hoge")
}

typealias Callback = (Int) -> Int
func someFunction(firstClosure: Callback? = nil,
                  secondClosure: Callback? = nil) {
    let first = firstClosure?(10)
    let second = secondClosure?(20)
    print(first ?? "-", second ?? "-")
}

someFunction { $0 } // - 20

感想

To ease migration of code ... the compiler checks both the left-to-right and right-to-left orderings. If the scan directions produce different results, the old right-to-left ordering is used and the compiler generates a warning. https://docs.swift.org/swift-book/ReferenceManual/Expressions.html