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 is_<type> Fix conditionals. #247

Merged
merged 12 commits into from
Jul 15, 2022
Merged

Add is_<type> Fix conditionals. #247

merged 12 commits into from
Jul 15, 2022

Conversation

blackwinter
Copy link
Member

@blackwinter blackwinter commented Jul 14, 2022

Implements a bunch of type-related conditionals from Catmandu.

  • Adds is_hash() as alias for is_object().
  • Adds is_empty() as new (semi-related) conditional.

Differs from Catmandu in that all scalars in Metafix are strings, we can't actually distinguish between boolean values and boolean strings or numeric values and numeric strings (that's also why is_true()/is_false() are hard-wired to strict: false).

@TobiasNx
Copy link
Collaborator

This integration test seems not to work: 29065de

@blackwinter
Copy link
Member Author

This integration test seems not to work: 29065de

Your input is not MARCXML! The records are empty (as the diff shows), because elementA is not recognized as MARCXML field.

@TobiasNx
Copy link
Collaborator

#### `is_string`

Executes the functions if/unless the field value is a string (and not a number).

saw this what about numbers that are strings? i think this is difficult to differentiate.

I would have not expected that the conditional is false, would have expected this do be true
https://github.com/metafacture/metafacture-fix/blob/77f6a97b4322b32e2327a7515cdb2eac66fc24af/metafix/src/test/resources/org/metafacture/metafix/integration/conditional/fromJson/toJson/ifIsStringsButNumbers

@blackwinter
Copy link
Member Author

That's just not how Catmandu behaves. Do you suggest breaking compatibility here?

@TobiasNx
Copy link
Collaborator

TobiasNx commented Jul 15, 2022

That's just not how Catmandu behaves. Do you suggest breaking compatibility here?

perhaps an option then?

if is_string("elementA", includeNumberStrings:"true")
  add_field("elementB", "Hello")
end

@fsteeg
Copy link
Member

fsteeg commented Jul 15, 2022

perhaps an option then?

I think the natural way to express that would be if we had boolean operators (#165):

if is_string(elementA) || is_number(elementA)

In the meantime, a workaround could be to call a macro from both if and elsif:

if is_string(elementA)
  call_macro(macroA)
elsif is_number(elementA)
  call_macro(macroA)
end

@blackwinter
Copy link
Member Author

Yes, boolean operators are at the top of my wish list now :)

Would you two agree to accept the implementation as is and maybe change it later depending on the outcome of LibreCat/Catmandu#393?

@fsteeg
Copy link
Member

fsteeg commented Jul 15, 2022

Would you two agree to accept the implementation as is and maybe change it later depending on the outcome of LibreCat/Catmandu#393?

+1

@TobiasNx
Copy link
Collaborator

Would you two agree to accept the implementation as is and maybe change it later depending on the outcome of LibreCat/Catmandu#393?

+1

Would you two agree to accept the implementation as is and maybe change it later depending on the outcome of LibreCat/Catmandu#393?

+1

+1 also all seem to work

@blackwinter blackwinter merged commit 8c90701 into master Jul 15, 2022
@blackwinter blackwinter deleted the addIsTypeConditionals branch July 15, 2022 13:41
@blackwinter
Copy link
Member Author

saw this what about numbers that are strings? i think this is difficult to differentiate.

Maybe we missed this earlier, but isn't the issue that Metafix doesn't have a numeric data type? Internally, all scalar values are strings.

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

Successfully merging this pull request may close these issues.

3 participants