Skip to content

Instantly share code, notes, and snippets.

Say more, more clearly, with @ceylon.

Gavin King gavinking

Say more, more clearly, with @ceylon.
View GitHub Profile
gavinking /
Created Aug 13, 2017 — forked from ceylonwebide/
Ceylon Web Runner: Solar System

Ceylon Solar System Example

This little example application demonstrates the use of Ceylon as an alternative to client-side JavaScript. In particular, the example shows:

  • a simple, typesafe, object-oriented program,
  • dependence on an external [cross-platform math module][xmath] written in Ceylon and hosted on
gavinking / proxy.ceylon
Last active Dec 6, 2016
Using Rank-2 polymorphic generic functions and JavaScript Proxy to create a typesafe proxy API for Ceylon objects
View proxy.ceylon
import ceylon.collection {
"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)`."
gavinking / main.ceylon
Created Dec 1, 2016
Ceylon Web Runner: Converting JavaScript Date to Ceylon DateTime
View main.ceylon
import ceylon.time { Instant, DateTime }
shared void run() {
dynamic {
//create a JavaScript Date
dynamic date = Date();
//convert it to a Ceylon DateTime
DateTime dt = Instant(date.getTime()).dateTime();
gavinking /
Last active Feb 7, 2018
Ceylon Web Runner: Records

Typesafe Records for Ceylon

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 records
  • keys.ceylon defines example typesafe keys
gavinking /
Last active Oct 17, 2016
Ceylon Web Runner: Ceylon Services

Ceylon Services Example

This tiny example demonstrates the use of Ceylon [service providers][] in the JavaScript environment. Service providers are an abstraction of, and [interoperate][] with, Java's [service loaders][], but are not tied to the Java platform, and can even work cross-platform.

gavinking / MaybeMonad.ceylon
Last active Mar 26, 2016
Emulating the Maybe monad in Ceylon
View MaybeMonad.ceylon
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
For the record: this is not idiomatic Ceylon. In
gavinking / xxxxByKey.ceylon
Last active Mar 22, 2016
reduceByKey() and foldByKey()
View xxxxByKey.ceylon
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)
View gist:8e6a019fcbbc474b7461
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 / 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 / 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
gavinking /
Last active Dec 4, 2015
silly verbosity comparison

Someone just told me that implementing an interface in F# is less vebose than in Ceylon. Let's see if that's true. Pick an example given on MSDN. (Yes, I know it's silly to make such trivial comparisons.)


View maven-log.txt
Gavins-New-MacBook-Pro:ceylon-dist gavin$ ant -Dbuild-against=last-release clean-ide eclipse
Buildfile: /Users/gavin/ceylon-dist/build.xml