-
Notifications
You must be signed in to change notification settings - Fork 0
case
Sergey Makeev edited this page Aug 29, 2019
·
2 revisions
An instance method of When class.
func `case`(_ condition: @escaping (Type) -> Bool, handler: (() -> Result?)? = nil) -> When<Type, Result> Get (Type) -> Bool block to be used as a condition. and handler to return the result.
Handler block could be omitted to combine several cases
In case of Result is Equtable
extension When where Type: Equatable {
func `case`(_ condition: Type, handler: (() -> Result?)? = nil) -> When<Type, Result>
}Here function takes a value of Type and check if this value is equal to value provided to When in it's constructor.
case returns a self of current When class and could be used as a chain.
...
.case(value){result1}
.case({$0 == something} {result2}
...The chain needs to be finished with call of default.