• Kipper

    v0.12.1
  • Downloads

  • Docs

  • Playground

  • Changelog

  • Kipper

    v0.12.1
    • Downloads

    • Docs

    • Playground

    • Changelog

      • next /
      • Expressions /
      • Matches Expression
    Kipper Docs
    • next
    • latest
    • 0.11.0
    • 0.10.4
    • 0.9.2
    • Overview

    • Quickstart

    • Goals for Kipper

    • Supported platforms

    • Usage Examples

      • Overview

    • Variables

      • Overview

      • String Type

      • Number Type

      • Boolean Type

      • Void Type

      • Null Type

      • Undefined Type

      • Array Type

      • Overview

      • Tangled Expression

      • Arithmetic Expression

      • Assignment Expression

      • Conditional Expressions

      • Logical Expressions

      • Bitwise Expression

      • Relational Expressions

      • Convert Or Cast Expression

      • F-String Expression

      • Member Access Expression

      • Function Call Expression

      • Lambda Expression

      • Matches Expression

      • Overview

      • Expression Statement

      • If Statement

      • While Loop

      • Do-While Loop

      • For Loop

      • Compound Statement

      • Jump Statement

    • Functions

    • Interfaces

    • Classes

    • Comments

    • Built-in Functions

      • Overview

      • Compiler Setup

        • Overview

          • index

          • compiler

          • errors

          • logger

          • utils

          • config

          • index

          • index

        • Overview

        • new

        • run

        • compile

        • help

        • version

      • next /
      • Expressions /
      • Matches Expression
    • next /
    • Expressions /
    • Matches Expression

    Edit page

    Matches Expression

    A matches expression is an expression used to pattern match a given value against a given interface blueprint type. It is used to check whether a value qualifies as a certain type (using the duck typing principle) and executes at runtime allowing any value to be checked.

    Syntax

    EXP matches INTERFACE

    Examples

    Matching a value against an interface

    interface SomeInterface {
        key: str;
    }
    var obj1: obj = { key: "value" };
    
    print(f"Object matches the interface: {obj1 matches SomeInterface}"); // -> true

    Matching a value against an interface with a nested interface

    interface NestedInterface {
        key: str;
    }
    
    interface SomeInterface {
        nested: NestedInterface;
        key2: bool;
    }
    
    var obj2: obj = { nested: { key: "value" }, key2: true };
    
    print(f"Object matches the interface: {obj2 matches SomeInterface}"); // -> true

    Matching a value with invalid property types against an interface

    interface SomeInterface {
        key: str;
        key2: bool;
        key3: num;
    }
    var obj3: obj = { key: "value", key2: "true", key3: 3 };
    
    print(f"Object matches the interface: {obj3 matches SomeInterface}"); // -> false

    Matching a value with missing properties against an interface

    interface SomeInterface {
        key: str;
        key2: bool;
        key3: num;
    }
    var obj4: obj = { key: "value" };
    
    print(f"Object matches the interface: {obj4 matches SomeInterface}"); // -> false

    Matching a value with additional properties against an interface

    interface SomeInterface {
        key: str;
        key2: bool;
        key3: num;
    }
    var obj5: obj = { key: "value", key2: true, key3: 3, key4: "extra" };
    
    print(f"Object matches the interface: {obj5 matches SomeInterface}"); // -> true
  • Developed at:

    • Releases
    • GitHub
    • Security
    • Issue Tracker
    • License
  • Copyright © 2021-2025 Luna Klatzer, 2024-2025 Lorenz Holzbauer & Fabian Baitura.
    Kipper is licensed under the GPL-3.0-or-later license.