Skip to content

Instantly share code, notes, and snippets.

@wotjd
Created May 23, 2019 04:42
Show Gist options
  • Save wotjd/b94afd2ca7dec67b4d94fddcd078d372 to your computer and use it in GitHub Desktop.
Save wotjd/b94afd2ca7dec67b4d94fddcd078d372 to your computer and use it in GitHub Desktop.
swift block scope idea for test (protocol not allowed)
import Foundation
public func FuntionScope(_ closure: () -> () ) {
closure()
}
public let TupleScope = { (c: () -> ()) in c() }
public let TupleExpScope: (() -> ()) -> () = { $0() }
// adding closure typealias
public typealias Closure<T> = (T) -> Void
public let TupleExpScopeWithTypealias: Closure<Closure<Void>> = { $0(()) }
public let scope = TupleExpScopeWithVoidTypealias
// usage
scope {
print("hi there?")
print("hello? i'm in here")
print("good")
}
// error
scope {
protocol AProtocol { ... } // Protocol 'AProtocol' cannot be nested inside another declaration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment