I am sorry but your new example is still incorrect, now even more. Translated back to natural languag it expresses the question:
Are all jobs named X in a healthy state?
If there is no job with name X then the answer is cleary yes. If you do not want it to be yes in this case then you are simply asking the wrong question. But not the wrong question in terms of swift methods but the wrong question even in natural language.
It's expected that logic reasoning abstracts from the specific content of an expression and only cares about the logical structure. Actually that's the whole point of logic in general. So in a sentence as above it is required by logic that you can replace words as "jobs", "name" or "health" with any other words of any domain an still get the same answers for all imaginable cases. For example
Are all numbers divisible X also devisible by 1?
(I replaced "jobs" with "numbers", "named" by "divisible" and "healthy" by "divisible by one")
Clearly the answer should always be true because all numbers a divisible by 1. Even all numbers divisible by 0 are divisible by 1, even though actually no number is divisible by zero.
The key is that the answer to such a logic question does never depend on your specific domain. From a logic perspective it does not matter if you are talking about jobs, requests or numbers.
Maybe one could imagine a method collectionNotEmptyAndAllSatisfy
that could be used to express your domain problem. But for me the issue seems to be that your problem statement is already wrong in natural language. Your method name is_job_healthy
already indicates that we are always talking about a specific job and not about possibly multiple jobs of the same name. So the natural language question to ask if a job named X being healthy would be:
Does there exist a job in the collection of all jobs whose name is X and is it's status healthy?
or
Does there exist a job in the collection of all jobs whose name is X and whose status is healthy?
So you can see that the logic structure needs an existence quantor, not an all quantor and a logical conjections (&&). So translated back to swift your function should look like:
func job_is_healthy(name: String) -> Bool {
return running_jobs.containsWhere { $0.name == name && $0.healthy }
}
containsWhere
corresponds to the existence quantor and is the opposite of allSatisfy
.
Now if you indeed want to support multiple jobs with the same name and check for all to be healthy than you would write:
func health_check(name: String) -> Bool {
return running_jobs.containsWhere { $0.name == name } &&
running_jobs.filter { $0.name == name }.allSatisfy { $0.healthy }
}
Natural language is not always very precise, so it's common to mix up existence and all quantors. But the key is to chose the right operators. In all given examples simply the term all
was used incorrectly and there is no way to change that by adding more options. Both all quantor and existence quantor are available. Maybe names like all
and exist
or every
and some
would be clearer, but you would still have to chose the right one to express what you really want.
There is a similar example for addition and substraction with numbers in form of a riddle:
you see a shirt for 97$ so you borrow 50$ from your mom and 50$ from your dad. you get 3 dollars back so you give 1 to your mom, 1 to your dad, and keep 1 for yourself. now you owe your mom 49$ and your dad 49$. 49$ + 49$= 98$ plus your 1$= 99$.... what happened to the other 1$.?
The solution is that the way the riddle is stated it mixes up dept and assets. Instead of 98+1 would has to to 98-1 to get back the 97$ price of the shirt. Adding 1 to 98 is meaningless in that context.
At first glance it seems that plus and minus are broken but then you see you just apply them in the wrong way. It's the same with logic. If you think the all quantor (allSatisfy) give the wrong answer then you are using it in the wrong place and probably need an existence quantor (containsWhere)