I wrote a simple function I wanted to use in my tests, to separate test phases into closures:
func given<T>(
_ setup: () -> T,
when: (inout T) -> Void = { _ in },
then: (T) -> Void
) {
var sut = setup()
when(&sut)
then(sut)
}
but I realized that if the given
closure is complex in some way the function won't compile:
It works if I explicitly write down the type of T
in the following closures, of I I use one-line given
closure. It works too if I extract the given
closure in a separate variable.
Does anybody know why this happens?
Is there a way swift compiler can infer the T
returned from given
closure?