Skip to content

Instantly share code, notes, and snippets.

@Viveron
Last active April 14, 2022 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Viveron/fae0b985392d85fb71787a7e6d0ca076 to your computer and use it in GitHub Desktop.
Save Viveron/fae0b985392d85fb71787a7e6d0ca076 to your computer and use it in GitHub Desktop.
public typealias Closure<Value, Result> = (Value) -> Result
public typealias ValueClosure<Value> = Closure<Value, Void>
public typealias ResultClosure<Result> = () -> Result
public typealias VoidClosure = ResultClosure<Void>
public typealias ThrowsClosure<Value, Result> = (Value) throws -> Result
public typealias ThrowsValueClosure<Value> = ThrowsClosure<Value, Void>
public typealias ThrowsResultClosure<Result> = () throws -> Result
public typealias ThrowsVoidClosure = ThrowsResultClosure<Void>
// OR
typealias Closure<Input, Output> = (Input) -> Output
typealias ValueClosure<Input> = Closure<Input, Void>
typealias ResultClosure<Output> = () -> Output
typealias VoidClosure = ResultClosure<Void>
typealias ThrowsClosure<Input, Output> = (Input) throws -> Output
typealias ThrowsValueClosure<Input> = ThrowsClosure<Input, Void>
typealias ThrowsResultClosure<Output> = () throws -> Output
typealias ThrowsVoidClosure = ThrowsResultClosure<Void>
// OR
typealias Closure<Input, Output> = (Input) -> Output
typealias InputClosure = Closure<Input, Void>
typealias OutputClosure = () -> Output
typealias VoidClosure = OutputClosure<Void>
typealias ThrowsClosure<Input, Output> = (Input) throws -> Output
typealias ThrowsInputClosure = ThrowsClosure<Input, Void>
typealias ThrowsOutputClosure = () throws -> Output
typealias ThrowsVoidClosure = ThrowsOutputClosure<Void>
@Viveron
Copy link
Author

Viveron commented Apr 14, 2022

var some: VoidClosure?
vs
var some: (() -> Void)?
...

func some(completion: ValueClosure<Bool>?)
vs
func some(completion: ((Bool) -> Void)?)
...

func request(completion: ValueClosure<Result<Data, Error>>?)
vs
func request(completion: ((Result<Data, Error>) -> Void)?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment