Feather2 / documentation / DuckOperators.md
Duck Operators
Feather doesn't use Kotlin-style operator
keyword.
Instead, Feather allows any method to be used as an operator if it has the correct name
and parameter types.
i.e. if it walks like an operator, and quacks like an operator, then it is an operator ;-)
For example, to use array-like
access :
foo[index]
Then foo
requires a function called get
, with a single parameter of type index
.
If it also has a set
or put
function, with 2 parameters (of the appropriate types),
then this can be used as an assignable expression. i.e. we can do :
foo[index] = value
This works with extension functions, as well as regular functions.