The example demonstrates the use of Ceylon's powerful type system to define typesafe heterogenous maps, otherwise known as record types.
records.ceylon
defines a tiny library for creating recordskeys.ceylon
defines example typesafe keys
"A generic function that produces a memoized version | |
of the given [[function|fun]]. Works for any function | |
arity." | |
Callable<Return,Args> memoize<Return,Args>(Callable<Return,Args> fun) | |
given Args satisfies Anything[] { | |
value cache = HashMap<Args,Return&Object|Finished>(); | |
function callFun(Args args) { | |
//we'll use finished as a convenient | |
//unit value to represent the case | |
//that the function returned null |
This little example application demonstrates the use of Ceylon as an alternative to client-side JavaScript. In particular, the example shows:
import ceylon.collection { | |
ArrayList | |
} | |
"Create a typesafe proxy for the given [[instance]], that | |
intercepts method calls and attribute evaluations." | |
Instance proxy<Instance>(Instance instance)(call, get) { | |
"Intercepts method invocations. Delegate to the method | |
of [[target]] by calling `method(args)`." |
import ceylon.time { Instant, DateTime } | |
shared void run() { | |
dynamic { | |
//create a JavaScript Date | |
dynamic date = Date(); | |
print(date); | |
//convert it to a Ceylon DateTime | |
DateTime dt = Instant(date.getTime()).dateTime(); | |
print(dt); |
/* | |
Demonstrates how to do monadic-style processing of | |
optional values in Ceylon. Represents an optional | |
type by boxing non-null values as singletons, and | |
the null value as the empty sequence. Monadic | |
operations are inherited from the stream interface, | |
with the caveat that m.flatMap(f) must be written | |
as m.flatMap(lift(f)) or as m.map(f).coalesced. | |
For the record: this is not idiomatic Ceylon. In |
shared Map<Key,Item> reduceByKey<Key,Item>( | |
{<Key->Item>+} stream, | |
Item accumulating(Item x, Item y)) | |
given Key satisfies Object | |
given Item satisfies Object | |
=> stream.summarize(Entry.key, | |
(Item? partial, entry) | |
=> let (_->item = entry) | |
if (exists partial) | |
then accumulating(partial, item) |
Description Location Resource Path Type | |
Access restriction: The constructor 'CoreException(IStatus)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.eclipse.ui/target/repo/plugins/org.eclipse.equinox.common-3.6.200.v20130402-1505.jar') line 123 AndroidBuildHookProvider.java /com.redhat.ceylon.eclipse.android.plugin/src/com/redhat/ceylon/eclipse/android/plugin Java Problem | |
Access restriction: The constructor 'Status(int, String, int, String, Throwable)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.eclipse.ui/target/repo/plugins/org.eclipse.equinox.common-3.6.200.v20130402-1505.jar') line 123 AndroidBuildHookProvider.java /com.redhat.ceylon.eclipse.android.plugin/src/com/redhat/ceylon/eclipse/android/plugin Java Problem | |
Access restriction: The constructor 'Status(int, String, String, Throwable)' is not API (restriction on required library '/Users/gavin/ceylon-ide-eclipse/plugins/com.redhat.ceylon.ecl |
import ceylon.collection { | |
LinkedList | |
} | |
import ceylon.math.float { | |
sin, | |
pi | |
} | |
"Map a function of arity `n` to a stream of values. In each |