notExists

Used in a template function to create a condition that is true if no matching fact exists.

static notExists<T>(
    template: T
): Condition<T>;

Parameters

  • template - A JSON object with the desired type and predecessors

Returns

  • A condition that can be used in suchThat or not

Examples

Return only facts that do not have a specified successor.

Blog Chat.Message Chat.Message Chat.Channel Chat.Channel Chat.Message->Chat.Channel channel Chat.Message.Redacted Chat.Message.Redacted Chat.Message.Redacted->Chat.Message message
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
    });
}

The above can be expressed in terms of exists and not. The result is the same.

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
    });
}

Double negatives are supported. They are just hard to read.

Blog Blog.Post Blog.Post Blog.Folder Blog.Folder Blog.Post->Blog.Folder folder Blog.Post.Published Blog.Post.Published Blog.Post.Published->Blog.Post post
function publishedPostsInFolder(f) {
    return j.match({
        type: 'Blog.Post',
        folder: f
    }).suchThat(j.not(postIsNotPublished));
}

function postIsNotPublished(p) {
    return j.notExists({
        type: 'Blog.Post.Published',
        post: p
    });
}

Continue With

not