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

Validate.IParamCollection.forAll #88

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Validate.IParamCollection.forAll #88

wants to merge 11 commits into from

Conversation

omaus
Copy link
Collaborator

@omaus omaus commented Feb 22, 2024

This PR

  • adds the forAll function in Validate.IParamCollection module/type
  • also adds an ErrorMessage.ofIParamCollection function according to this
    • provides a unit test for this functionality

@omaus omaus requested a review from kMutagene February 22, 2024 17:43

static member ofIParamCollection error iParamCollection =

let iParam = Seq.head iParamCollection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not get these functions to be honest. The API naming indicates that it generates error messages from IParam collections, but you only use the first item in the sequence to generate the error message

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since printing all items would be too much. I mean, this is arbitrary. How many items do we want to display? I chose 1, but we could also do 3 or 5 or any number...
What's your opinion on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, this is arbitrary.

Not really, ideally you want to know all items that do not satisfy the predicate

match Seq.forall projection paramCollection with
| true -> ()
| false ->
ErrorMessage.ofIParamCollection $"does not exist" paramCollection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"does not exist" is not the correct error message here i think. since this should check wether the projection is true for all values, the same message as ValueSatisfiesPredicate ("is invalid) makes more sense.

However, there are 2 more issues here:

  • please rename to ValuesSatisfyPredicate, as that is the name of the respective function for a single IParam. That way, it becomes Validate.ParamCollection .ValuesSatisfyPredicate ("Validate (for a) ParamCollection (that the) values satisfy (the) predicate")
  • the error message seems to make even less sense to me combined with the new ErrorMessage.ofIParamCollection, since that uses the head of the sequence. Imagine the second value does not satisfy the predicate - but the error message uses the first - this is very confusing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just not about the Value but about the whole IParam. So the naming should be ParamsSatisfyPredicate.

To the second point: What would you think about reformulating the function so that it does not use Seq.forAll but iterates through the seq so that we can catch the failing IParams and return them?

Copy link
Member

@kMutagene kMutagene Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just not about the Value but about the whole IParam

Ideally we would have all 3 variants for Param and ParamCollection.

Thinking again about this, i guess the names of the colelction versions should be a little different.

My suggestions would be

  • Param.SatisfiesPredicate
  • Param.TermSatisfiesPredicate
  • Param.ValueSatisfiesPredicate
  • ParamCollection.ItemsSatisfyPredicate
  • ParamCollection.TermsSatisfyPredicate
  • ParamCollection.ValueySatisfyPredicate

@kMutagene
Copy link
Member

@omaus how do you intend to proceed on this? for reference, the new API design guidelines are here: https://nfdi4plants.github.io/arc-validate/ARCExpect/design.html.

Do you intend to start with a fresh PR or adapt the code in this one?

@omaus
Copy link
Collaborator Author

omaus commented Feb 29, 2024

@omaus how do you intend to proceed on this? for reference, the new API design guidelines are here: https://nfdi4plants.github.io/arc-validate/ARCExpect/design.html.

Do you intend to start with a fresh PR or adapt the code in this one?

This is just about renaming, isn't it? So it should be much easier to just rename the functions instead of writing everything anew.

@omaus
Copy link
Collaborator Author

omaus commented Mar 7, 2024

I updated the function's name to fit the naming design and also changed it in a way that the first param that does not satisfy the predicate is shown instead of a part of the whole collection.

/// </summary>
/// <param name="projection">A function that evaluates to true if the element satisfies the requirements.</param>
/// <param name="paramCollection">The IParam collection to validate.</param>
static member ParamsSatisfyPredicate (predicate : #IParam -> bool) (paramCollection : #seq<#IParam>) =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls rename to AllItemsSatisfyPredicate as of https://nfdi4plants.github.io/arc-validate/ARCExpect/design.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(also xml docs and function parameters do not match)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. 👍

@omaus
Copy link
Collaborator Author

omaus commented Mar 7, 2024

and also changed it in a way that the first param that does not satisfy the predicate is shown instead of a part of the whole collection.

Btw. is this okay or would you prefer to show all predicate failing items?

@omaus
Copy link
Collaborator Author

omaus commented Mar 8, 2024

and also changed it in a way that the first param that does not satisfy the predicate is shown instead of a part of the whole collection.

Btw. is this okay or would you prefer to show all predicate failing items?

Okay, tweaked it so that it goes throw the whole collection.

@omaus omaus requested a review from kMutagene March 8, 2024 16:57
@@ -165,6 +165,7 @@ module Validate =
if predicate en.Current |> not then
ErrorMessage.ofIParam $"does not satisfy predicate" en.Current
|> Expecto.Tests.failtestNoStackf "%s"
loop ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested wether this continues after 1 failtestNoStackf is executed? If that throws an exception i am quite sure that it wont

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. It is more complicated to do this than I thought...
But I think I'll get a solution.

@omaus omaus requested a review from kMutagene March 11, 2024 16:22
str.ToString()


static member ofIParamCollection error iParamCollection =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used anymore in the current state of the PR is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omaus omaus requested a review from kMutagene April 23, 2024 13:30
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

Successfully merging this pull request may close these issues.

None yet

2 participants