Skip to content

Instantly share code, notes, and snippets.

View gavinking's full-sized avatar
💭
Say more, more clearly, with @ceylon.

Gavin King gavinking

💭
Say more, more clearly, with @ceylon.
View GitHub Profile
@gavinking
gavinking / README.md
Created August 13, 2017 14:56 — forked from ceylonwebide/README.md
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
gavinking / proxy.ceylon
Last active December 6, 2016 19:13
Using Rank-2 polymorphic generic functions and JavaScript Proxy to create a typesafe proxy API for Ceylon objects
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)`."
@gavinking
gavinking / main.ceylon
Created December 1, 2016 20:53
Ceylon Web Runner: Converting JavaScript Date to Ceylon DateTime
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);
@gavinking
gavinking / README.md
Last active February 7, 2018 09:42
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
gavinking / README.md
Last active October 17, 2016 07:18
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
gavinking / MaybeMonad.ceylon
Last active March 26, 2016 10:44
Emulating the Maybe monad in 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 m.map(f).coalesced.
For the record: this is not idiomatic Ceylon. In
@gavinking
gavinking / xxxxByKey.ceylon
Last active March 22, 2016 10:22
reduceByKey() and foldByKey()
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)
@gavinking
gavinking / gist:8e6a019fcbbc474b7461
Last active February 29, 2016 16:42
IDE build errors
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
@gavinking
gavinking / verbosity.md
Last active December 4, 2015 15:01
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.)

F#

@gavinking
gavinking / maven-log.txt
Last active November 2, 2015 15:24
Failing build
Gavins-New-MacBook-Pro:ceylon-dist gavin$ ant -Dbuild-against=last-release clean-ide eclipse
Buildfile: /Users/gavin/ceylon-dist/build.xml
clean-ide:
siblings:
clean:
clean-item: