Implement a match operator which matches any type against an interface. This is a simple wrapper of all the type functionality present in Kipper, which allows the user to match anything against a Kipper type.
This means the following:
match can compare primitives to a specific type:
1 match num; // -> true
"2" match str; // -> true
true match null; // -> false
match can compare arrays to Array and functions to Func:
[1, 2, 3] match Array<num>; // -> true
(): void -> {} match Func<void> // -> true
(): num -> 1 match Func<void> // -> false
As such, match is also not identical to typeof or instanceof. typeof returns obj for every object in the language and as such can not be used to compare interface types, while instanceof is limited to a prototype being present i.e. a class instance being compared to another class.
Exact behaviour / changes you want
[x] #495
[x] #659
[x] Implement a built-in match operator which matches any given expression to a given type specifier.
[x] Implement internal functionality for the match operator.
Is there an existing proposal for this?
This feature does not exist in the latest version
Proposal
Implement a
match
operator which matches any type against an interface. This is a simple wrapper of all the type functionality present in Kipper, which allows the user to match anything against a Kipper type.This means the following:
match
can compare primitives to a specific type:match
can compare objects to interface types:match
can compare arrays toArray
and functions toFunc
:As such,
match
is also not identical totypeof
orinstanceof
.typeof
returnsobj
for every object in the language and as such can not be used to compare interface types, whileinstanceof
is limited to a prototype being present i.e. a class instance being compared to another class.Exact behaviour / changes you want
match
operator which matches any given expression to a given type specifier.match
operator.