A generic function used through dynamic functions
The complete source of structure_generic_function.ek9, compiled by the EK9 compiler. Shown on structure.html.
#!ek9 defines module site.structure.genericfunction defines function compareFunction() of type T as open -> item1 as T item2 as T <- rtn as Integer: item1 <=> item2 defines program ComparatorDemo() stdout <- Stdout() intComparator <- () is compareFunction of Integer as function stringComparator <- () extends compareFunction of String as function intResult <- intComparator(2, 8) stringResult <- stringComparator("two", "eight") stdout.println(`Result of int comparison is ${intResult}`) stdout.println(`Result of string comparison is ${stringResult}`)
Download structure_generic_function.ek9
Output
Result of int comparison is -1 Result of string comparison is 15