RelationalAI-oss / Rematch.jl

Pattern matching
Other
52 stars 6 forks source link

Interface to match with a list of patterns #23

Open MasonProtter opened 4 years ago

MasonProtter commented 4 years ago

Currently, it seems the only API to use pattern matching with this package is with the provided macros. However, sometimes I want to generate a list of patterns and then do pattern matching using those instead of manually writing out all my patterns inside the macro.

It'd be really great if there was an API to do something like this:

const global_pats = [:(_::String   => :string)
                     :([a,a,a]     => (:all_the_same, a))
                     :([a,bs...,c] => (:at_least_2, a, bs, c))]

f(x) = match(x, global_pats)

julia> f("foo")
:string