[RFC] Qo 0.5.0 API


(Brandon Weaver) #1

*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.

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

- Brandon (baweaver)


(Don Wilde) #2

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.

···

On 8/7/18, Brandon Weaver <keystonelemur@gmail.com> wrote:

*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)

--
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.


(Brandon Weaver) #3

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

···

On Tue, Aug 7, 2018 at 8:09 AM Donald Wilde <dwilde1@gmail.com> wrote:

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.

On 8/7/18, Brandon Weaver <keystonelemur@gmail.com> wrote:
> *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)
>

--
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-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>