This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Element[] quicksort<Element>({Element*} elements) | |
given Element satisfies Comparable<Element> => | |
if (exists first = elements.first) | |
then [first.largerThan, first.notLargerThan] | |
.map(compose(quicksort<Element>, elements.rest.filter)) | |
.interpose([first]) | |
.reduce(concatenate<Element>) | |
else []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ceylon.collection { | |
LinkedList | |
} | |
import ceylon.dbc { | |
Sql, | |
newConnectionFromDataSource | |
} | |
import ceylon.interop.java { | |
javaClass | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a comparison between Scala and Ceylon based on this previous comparison I made between Haskell and Groovy: | |
// https://gist.github.com/renatoathaydes/5078535 | |
// Ex 1. If we have two lists, [2,5,10] and [8,10,11] and we want to get the products of all the possible | |
// combinations between numbers in those lists, here's what we'd do. | |
/* SCALA */ | |
for { x <- List(2,5,10); y <- List(8,10,11) } yield x*y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// enum 1 of application i18n keys | |
abstract class AppKeyi18n() | |
of title | description {} | |
object title extends AppKeyi18n() {} | |
object description extends AppKeyi18n() {} | |
// enum 2 of user i18n keys | |
abstract class UserKeyi18n() | |
of fieldText1 | fieldText2 | fieldText3 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent { | |
Callable, | |
ScheduledThreadPoolExecutor | |
} | |
void execute(Integer numberOfTasks) { | |
value n = 1G; // same number of iterations as Java | |
value delta = 1.0 / n; | |
value startTime = process.nanoseconds; | |
value sliceSize = n / numberOfTasks; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shared void run() => printAll { for (i in 0..50) fizzbuzz(i) }; | |
String fizzbuzz(Integer i) | |
=> (i%15==0 then "fizzbuzz") | |
else (i%3==0 then "fizz") | |
else (i%5==0 then "buzz") | |
else i.string; | |
void printAll({String*} strings) => print(", ".join(strings)); |