Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add catmandu selector select() #271

Open
TobiasNx opened this issue Nov 21, 2022 · 6 comments
Open

Add catmandu selector select() #271

TobiasNx opened this issue Nov 21, 2022 · 6 comments

Comments

@TobiasNx
Copy link
Collaborator

No description provided.

@blackwinter
Copy link
Member

Can you provide a use case?

@TobiasNx
Copy link
Collaborator Author

In context of OERSI I wanted to use it for filtering records, since we had multiple positive contitions:

if exists("name")
  if exists("license")
    if exists("creator[]")
      select()
    end
  end
end

I ended up using:

unless exists ("name")
  reject()
end

unless exists ("license")
  reject()
end

unless exists ("creator[]")
  reject()
end

@blackwinter
Copy link
Member

So you also need "reject unless selected" behaviour? That's not what select() does, AFAIUI. Only with a condition (select() <condition>), which our grammar currently doesn't support.

I'm not even sure, though, if select() <condition> would work here:

select() exists("name")
select() exists("license")
select() exists("creator[]")

Wouldn't a subsequent select() override a previous rejection?

You could, however, combine your reject() conditions:

if exists("name")
elsif exists("license")
elsif exists("creator[]")
else
  reject()
end

@blackwinter
Copy link
Member

So you also need "reject unless selected" behaviour?

Scratch that. This can always be achieved with an unconditional reject() at the start.

@TobiasNx
Copy link
Collaborator Author

So you also need "reject unless selected" behaviour? That's not what select() does, AFAIUI. Only with a condition (select() <condition>), which our grammar currently doesn't support.

Is "reject unless selected" not the functionality that what select() would provide.

I'm not even sure, though, if select() <condition> would work here:

select() exists("name")
select() exists("license")
select() exists("creator[]")

Wouldn't a subsequent select() override a previous rejection?

I would assume they would narrow this down? But it would be something like: select() exists("name") && exists("license") && exists("creator[]") But I am not sure.

You could, however, combine your reject() conditions:

if exists("name")
elsif exists("license")
elsif exists("creator[]")
else
  reject()
end

Thanks. I think what perhaps confuses you is that while I have a combined condition the rejection condition can be separated:
"name", "license", "creator[]" must all exist to be selected. One or two of them would be not enough and those records can be rejected. Therefore if one of them does not exists the can be rejected..

Your workaround could not handle this. Since it would only check if the "name", "license" or "creator[]" exist.

if exists("name")
  if exists("license")
    if exists("creator[]")
    else
     reject()
   end
  else
    reject()
  end
else
  reject()
end

But anyway it is not urgent.

@blackwinter
Copy link
Member

Is "reject unless selected" not the functionality that what select() would provide.

How? If any of your conditions doesn't hold, the select() call is never reached. That's why I said select() <condition> would be required. This is equivalent to

if <condition>
  select()
else
  reject()
end

I would assume they would narrow this down?

That would be odd, IMO. But we'd have to check with Catmandu to know for sure.

But it would be something like: select() exists("name") && exists("license") && exists("creator[]")

If we had boolean operators (#165), you wouldn't be asking for select() ;)

unless exists("name") && exists("license") && exists("creator[]")
  reject()
end

"name", "license", "creator[]" must all exist to be selected.

Indeed! Sorry about that!

So there's currently no way of simplifying your use case and it's dubious whether select() would help at all. In order to proceed, we'd need to specify the interactions of multiple selectors (combinations of select()s and/or reject()s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants