DevHeads.net

Qo 0.5.0 API

*What's Qo?*

Qo is a pattern matching implementation in pure Ruby.

It lets you do things like this:

Qo.case(['Foo', 42]) { |m|
m.when(/^F/, Any) { 'Foo!' }
m.else { 'Not foo...' }
}
=> 'Foo!'

[['Foo', 42], ['Bar', 24]].map(&Qo.match { |m|
m.when(/^F/, Any) { 'Foo!' }
m.else { 'Not foo...' }
})
=> ['Foo!', 'Not foo...']

The syntax purposely mimics case statements.

*RFC*

Working on refining the API for Qo, mostly modeled after the 2.6+ potential
Hash#=== and Array#=== features. If these two are merged, Qo will likely
get substantially faster. The only thing these don't do are Hash vs Object
matches.

I'd be curious to get any opinions on the API so far, as I want to drive it
a bit more towards a stable set going into the next few versions before I
pull the 1.0.0 switch.

<a href="https://github.com/baweaver/qo/pull/20" title="https://github.com/baweaver/qo/pull/20">https://github.com/baweaver/qo/pull/20</a>

So if you have any opinions on pattern matching in general, I'd be
interested to hear them

- Brandon (baweaver)