An abstract function, two functions that extend it, and a delegate
The complete source of structure_filter.ek9, compiled by the EK9 compiler. Shown on structure.html.
#!ek9 defines module site.structure.filter defines function //Just a function signature. stringFilter() as abstract -> string as String <- rtn as Boolean? nonColon() extends stringFilter() -> string as String <- rtn as Boolean: ":" <> string isSet() extends stringFilter() -> string as String <- rtn as Boolean: string? defines program TestFilter() stdout <- Stdout() toTest <- "Steve" if nonColon(toTest) stdout.println(toTest + " does not have a colon") else stdout.println(toTest + " does have a colon") //It is also possible via delegate access acceptable as stringFilter := nonColon if acceptable(toTest) stdout.println(toTest + " does not have a colon") //As a delegate we can swap the function out for another compatible one. acceptable = isSet if not acceptable(toTest) stdout.println("The value toTest is not set")
Output
Steve does not have a colon Steve does not have a colon