Skip to content

Simplified syntax based on pampy.js #9

@jarble

Description

@jarble

I found a library called pampy.js that provides a very concise syntax for pattern matching. If this library were translated into PHP, then functional-php's pattern matching might look like this, using a variadic function to match patterns instead of an array:

function fib($n) {
    return match($n,
        1, 1,
        2, 1,
        _, function($x){ return fib($x - 1) + fib($x - 2); }
        //each underscore is passed as an argument to a function, so there can be several 
    );
}

Would it be possible to translate pampy.js to PHP so that the patterns could be matched in this way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions