LoginSignup
5
4

More than 5 years have passed since last update.

SwiftのFunctionタイプもextensionしてみたい...

Posted at

いろんなタイプをextensionしまくって味をしめてしまうと,関数タイプも,と欲が止まりません.
気分としては,こんな感じで.

extension (Int) -> Int {
    funtionHook($0)  // フックして色々チェックとか.
    return self($0)  // 本来のボディーを起動. 
}

とか,

extension (Int) -> Int {
    return posingFunction($0)  // さりげなく関数を差し替える
}

とか.
できると面白いと思うのですが,コンパイラ様は,
"Non-nominal type '(Int) -> Int' cannot be extended"とご立腹です.

2番目のは危ないのでダメとしても,1番目のは言語機能として認めて欲しいところです.

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4