Used in a template function to create a condition that is true if a matching fact exists.
static exists<T>(
template: Partial<T>
): Condition<T>;
type
and predecessorssuchThat
or not
Return only facts that have a specified successor.
function publishedPostsInFolder(f) {
return j.match({
type: 'Blog.Post',
folder: f
}).suchThat(postIsPublished);
}
function postIsPublished(p) {
return j.exists({
type: 'Blog.Post.Published',
post: p
});
}
Return only facts that do not have a specified successor.
function messagesInChannel(c) {
return j.match({
type: 'Chat.Message',
channel: c
}).suchThat(j.not(messageIsRedacted));
}
function messageIsRedacted(m) {
return j.exists({
type: 'Chat.Message.Redacted',
message: m
});
}
The above can be expressed in terms of notExists
.
The result is the same.
function messagesInChannel(c) {
return j.match({
type: 'Chat.Message',
channel: c
}).suchThat(messageIsNotRedacted);
}
function messageIsNotRedacted(m) {
return j.notExists({
type: 'Chat.Message.Redacted',
message: m
});
}