summaryrefslogtreecommitdiff
path: root/tests/examplefiles/example.ceylon
blob: b136b9951d51890b7c13783f9d43339c15b3d25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
doc "A top-level function,
     with multi-line documentation."
void topLevel(String? a, Integer b=5, String... seqs) {
    function nested(String s) {
        print(s[1..2]);
        return true;
    }
    for (s in seqs.filter((String x) x.size > 2)) {
        nested(s);
    }
    value uppers = seqs.sequence[].uppercased;
    String|Nothing z = a;
    Sequence<Integer> ints = { 1, 2, 3, 4, 5 };
}

shared class Example<Element>(name, element) satisfies Comparable<Example<Element>>
        given Element satisfies Comparable<Element> {
    shared String name;
    shared Element element;

    shared actual Comparison compare(Example<Element> other) {
        return element <=> other.element;
    }

    shared actual String string {
        return "Example with " + element.string;
    }
}

Example<Integer> instance = Example {
    name = "Named args call";
    element = 5;
};