<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">AFAIK there isn't currently a way of matching if an Any instance is a closure:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> something<T>(x: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <font color="#008400" class="">/// is x a function? We want to support Any (Int, Int32, Float, Double,</font></span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> <font color="#008400" class="">/// </font></span><span style="color: rgb(0, 132, 0);" class=""> </span><span style="color: rgb(0, 132, 0);" class="">AnyObject, ...), </span><span style="color: rgb(0, 132, 0);" class="">but disallow functions.</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> ...</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; min-height: 10px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> myClosure = { </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Hello"</span><span style="font-variant-ligatures: no-common-ligatures" class="">) }</span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">something</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">myClosure</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">) // Don't allow this.</span></div></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div style="margin: 0px; font-size: 9px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div class="">I propose adding a protocol Function - all closures would conform to it. See the code on </div><div class=""><br class=""></div><div class=""><a href="https://gist.github.com/charlieMonroe/655f2b5e25cc0b4ba06c0ddafa41c73b" class="">https://gist.github.com/charlieMonroe/655f2b5e25cc0b4ba06c0ddafa41c73b</a></div><div class=""><br class=""></div><div class="">which outlines the API and possible usage of it:</div><div class=""><br class=""></div><div class="">- Allowing to match a function from an Any instance.</div><div class="">- Inspect the function object - arguments, captured values, return type. This may help debugging retain cycles by printing the catputred variables - you will be able to see `self` within these.</div><div class="">- Invocation - creating something as NSInvocation, since you'd be able to call the function with a list of arguments.</div><div class="">- This could also become a basis for some RPC in Swift.</div><div class=""><br class=""></div><div class="">I know this is partially something for the Reflection discussion going on here as well as something for the existentials, but since it kind of overlapses both discussions, I thought creating a new thread would perhaps be beneficial.</div><div class=""><br class=""></div><div class="">Charlie</div><div class=""><br class=""></div></body></html>