Skip to content

Instantly share code, notes, and snippets.

@aruld
Last active January 1, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruld/8172945 to your computer and use it in GitHub Desktop.
Save aruld/8172945 to your computer and use it in GitHub Desktop.
void main() {
value employees = {"neal", "s", "stu", "j", "rich", "bob"};
String result = ",".join(employees
.filter((String e) => e.longerThan(1))
.map((String s) => s.segment(0, 1).uppercased + s.spanFrom(1))
);
// using a for comprehension
String result = ", ".join {
for (i in employees)
if (i.longerThan(1))
i.segment(0, 1).uppercased + i.spanFrom(1)
};
}
@gavinking
Copy link

Just stumbled upon this. A couple of suggestions:

  1. As of Ceylon 1.1, the explicit type annotations in the anonymous functions are no longer required.
  2. We usually write x.segment(0, 1) as x[0:1], and x.spanFrom(1) as x[1...].

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment