<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Hi all,</div><div class=""><br class=""></div><div class="">Similar to the syntax ‘do try catch throw’ and ’throws’ for error handling, I propose another syntax for handling CPS functions or async call backs:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> someFutureWrappedFunc(input: <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Int</span>) <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">future</span>-> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">String</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>doSomeStaffInBackground<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{ (result:</span>String<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">fulfil</span> result</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><span class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class="">}</div></span></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class="">do<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> resultX = </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">perform</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>someFutureWrappedFunc<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span>param<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> resultY = <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">perform</span> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">anotherFutureWrappedFunc</span>(resultX)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><div style="margin: 0px; line-height: normal;" class=""> <span style="color: rgb(4, 51, 255);" class="">let</span> final = resultX + resultY + <span style="color: rgb(4, 51, 255);" class="">perform</span> <span style="color: rgb(52, 149, 175);" class="">justAnotherFutureWrappedFunc</span>(resultX)</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">someLabel</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">text</span> = final</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">} <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">timeout</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> context {</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> //maybe some additional information<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">the reason for this proposal is for the importance of async models in modern application architectures, and avoid such pyramids:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(52, 149, 175);" class="">doSomeStaffInBackground<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> { (resultX) -> </span>Void<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">doSomeOtherStaff</span> { (resultY) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">if</span> resultY.<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">someCondition</span>(resultX) {</div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">evenMakesItMadness</span>(resultY) { (final) -> <span style="color: rgb(52, 149, 175);" class="">Void</span> <span style="color: rgb(4, 51, 255);" class="">in</span></div><p style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #008f00" class="">//finally</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">For more context comparing this async syntax to the ‘do try catch’:</div><div class=""><br class=""></div><div class="">do try catch:</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">enum</span> Result<T> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> Success(T)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> Failure(ErrorType)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> flatMap<T,U> (result:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Result</span><<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span>>, f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Result</span><<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Result</span><<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">switch</span> result{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> .Success(<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> v): <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> f(v)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> .Failure(<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> e): <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Failure</span>(e)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> wrap1<T,U>(f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">throws</span>-> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Result</span><<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">do</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">try</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Success</span>(f($0))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">catch</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> e{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> .<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Failure</span>(e)</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> wrap2<T,U>(f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Result</span><<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">throws</span>-> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">switch</span> f($0){</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> .Success(<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> v): <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> v</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span> .Failure(<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span> e): <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">throw</span> e</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class="">async:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> flatMap<T,U> (async: (<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>, f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> -> (<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>) -> (<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span> -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span>{ cont <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> async{ f($0)(cont) }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> wrap1<T,U>(f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> <span style="color: rgb(4, 51, 255);" class="">future</span>-> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span>->(<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>)-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">return</span> {input <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> {cont <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">in</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">do</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> cont(<span style="color: rgb(4, 51, 255);" class="">perform</span> f(input))</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }<span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">catch</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">_</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span> wrap2<T,U>(f:<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span> -> (<span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>)-><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span>) -> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T </span><span style="color: rgb(4, 51, 255);" class="">future</span>-> <span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span>{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(4, 51, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> f(input)({</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(4, 51, 255);" class="">fulfil</span> $0</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> })</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>