-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
|
||
static member ofIParamCollection error iParamCollection = | ||
|
||
let iParam = Seq.head iParamCollection |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
src/ARCExpect/ValidationFunctions.fs
Outdated
match Seq.forall projection paramCollection with | ||
| true -> () | ||
| false -> | ||
ErrorMessage.ofIParamCollection $"does not exist" paramCollection |
There was a problem hiding this comment.
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 singleIParam
. That way, it becomesValidate.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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
@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. |
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. |
src/ARCExpect/ValidationFunctions.fs
Outdated
/// </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>) = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. 👍
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. |
src/ARCExpect/ValidationFunctions.fs
Outdated
@@ -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 () |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
str.ToString() | ||
|
||
|
||
static member ofIParamCollection error iParamCollection = |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR
forAll
function inValidate.IParamCollection
module/typeErrorMessage.ofIParamCollection
function according to this