Discussion:
[RFC] Qo 0.5.0 API
Brandon Weaver
2018-08-07 07:09:48 UTC
Permalink
*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.

https://github.com/baweaver/qo/pull/20

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

- Brandon (baweaver)
Donald Wilde
2018-08-07 15:08:48 UTC
Permalink
I like the when... else syntax. I'd add a negation 'when not'. Do you
want to have multi-level matching or not? ('else if') Personally, I
think not. The simplicity of what you are starting with is compelling.
Post by Brandon Weaver
*What's Qo?*
Qo is a pattern matching implementation in pure Ruby.
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.
https://github.com/baweaver/qo/pull/20
So if you have any opinions on pattern matching in general, I'd be
interested to hear them
- Brandon (baweaver)
--
Don Wilde

"Social programming generates beliefs, beliefs create attitudes,
attitudes cause feelings, feelings cause us to act, and actions
produce results -- good or bad." -- adapted from "What to Say When You
Talk to Yourself," by Shad Helmstetter, Ph. D.

Unsubscribe: <mailto:ruby-talk-***@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Brandon Weaver
2018-08-07 18:19:11 UTC
Permalink
That's the fun thing, Qo has inverse matchers and or matchers as well:

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

I may make that more succinct later, but I'd need to think it through
Post by Donald Wilde
I like the when... else syntax. I'd add a negation 'when not'. Do you
want to have multi-level matching or not? ('else if') Personally, I
think not. The simplicity of what you are starting with is compelling.
Post by Brandon Weaver
*What's Qo?*
Qo is a pattern matching implementation in pure Ruby.
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
Post by Brandon Weaver
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
Post by Brandon Weaver
matches.
I'd be curious to get any opinions on the API so far, as I want to drive
it
Post by Brandon Weaver
a bit more towards a stable set going into the next few versions before I
pull the 1.0.0 switch.
https://github.com/baweaver/qo/pull/20
So if you have any opinions on pattern matching in general, I'd be
interested to hear them
- Brandon (baweaver)
--
Don Wilde
"Social programming generates beliefs, beliefs create attitudes,
attitudes cause feelings, feelings cause us to act, and actions
produce results -- good or bad." -- adapted from "What to Say When You
Talk to Yourself," by Shad Helmstetter, Ph. D.
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Loading...