A readable stream pipeline over people
The complete source of introduction_pipeline.ek9, compiled by the EK9 compiler. Shown on introduction.html.
#!ek9 defines module site.introduction.pipeline defines record Person first as String: String() last as String: String() dob as Date: Date() profession as String: String() default Person() as pure Person() as pure -> first as String last as String dob as Date profession as String this.first :=? first this.last :=? last this.dob :=? dob this.profession :=? profession default operator ? operator $ as pure <- rtn as String: `${first} ${last}` defines function lastNameAndDob() as pure -> p as Person <- rtn as String: `${p.last} ${p.dob}` lastNameComparison() as pure -> p1 as Person p2 as Person <- rtn as Integer: p1.last <=> p2.last personProfession() as pure -> p as Person <- rtn as String: p.profession professionComparison() as pure -> group1 as List of Person group2 as List of Person <- rtn as Integer: group1.getOrDefault(0, Person()).profession <=> group2.getOrDefault(0, Person()).profession personToString() as pure -> group as List of Person <- rtn as String: $ group defines program Preview() stdout <- Stdout() people <- [ Person(first: "Jane", last: "Doe", dob: 1980-03-04, profession: "Doctor"), Person(first: "John", last: "Smith", dob: 1960-01-01, profession: "IT"), Person(first: "Anne", last: "Jones", dob: 1972-05-06, profession: "Engineer"), Person(first: "John", last: "Smith", dob: 1960-01-01, profession: "IT"), Person(first: "Bill", last: "Adams", dob: 1990-07-08, profession: "Doctor") ] cat people | uniq by lastNameAndDob | sort with lastNameComparison | group by personProfession | sort by professionComparison | map with personToString > stdout cat people | uniq by lastNameAndDob | sort with lastNameComparison | group by personProfession | sort by professionComparison | map with personToString > stdout
Download introduction_pipeline.ek9
Output
[Bill Adams, Jane Doe] [Anne Jones] [John Smith] [Bill Adams, Jane Doe] [Anne Jones] [John Smith]