Ceylon (programming language): Difference between revisions

Content deleted Content added
BG19bot (talk | contribs)
m WP:CHECKWIKI error fix for #61. Punctuation goes before References. Do general fixes if a problem exists. - using AWB (11751)
Briefly describe Ceylon functions including syntax.
Line 132:
the result will be a stream of <code>&lt;Integer|Null&gt; & Object</code> elements,
which simplifies to <code>Integer</code>.
 
==== Functions ====
Similarly to many modern languages, Ceylon suports first class functions and higher order functions, including function types and anonymous functions <ref>{{cite web|last=King|first=Gavin|title=The Ceylon Language: 4.7 Functions |url=http://ceylon-lang.org/documentation/1.2/spec/html/declarations.html#functions|accessdate=5 December 2015}}</ref>
 
<source lang="ceylon">
// A top-level higher-order function using block syntax (not associated with any user-created classes)
String process(String text, String transformString(String toChange)) {
return transformString(text);
}
 
// A top-level function calling String.reverse in expression form.
String reverse(String text) => text.reversed;
 
// A function reference to String.reversed but mostly equivalent to the function above.
String(String) reverseFunctionReference = String.reversed;
 
// An example where the top-level function above is provided as an argument to the higher-order function above
String reversed1 = process("one", reverse);
 
// Any example where an anonymous function - (text) => text+text - is provided to the higher-order function above.
String reversed2 = process("one", (text) => text+text);
</source>
 
==== Type Inference ====