then

Extend a preposition chain.

then<V>(
    specification: (target: U) => Specification<V>
    ): Preposition<U, V>;

Parameters

  • specification - A template function, which returns j.match

Returns

  • A preposition that can be passed to query or watch, or used to construct a preposition chain

Examples

Build a preposition chain.

Blog Blog.Post Blog.Post Blog.Person Blog.Person Blog.Post->Blog.Person author Blog.Post.Tags Blog.Post.Tags Blog.Post.Tags->Blog.Post post
function postsByAuthor(a) {
    return j.match({
        type: 'Blog.Post',
        author: a
    });
}

function tagsForPost(p) {
    return j.match({
        type: 'Blog.Post.Tags',
        post: p
    });
}

const tags = await j.query(person, j
    .for(postsByAuthor)
    .then(tagsForPost));

The above can be combined into a single template function. But some queries cannot be. For example, the following is a zig-zag query. It starts by selecting successors. Then it jumps up to a different predecessor, and then back down to different successors.

Blog Blog.Post.Tags Blog.Post.Tags Blog.Tag Blog.Tag Blog.Post.Tags->Blog.Tag * tags Blog.Post Blog.Post Blog.Post.Tags->Blog.Post post Blog.Post.Title Blog.Post.Title Blog.Post.Title->Blog.Post post Blog.Post.Title->Blog.Post.Title * prior
function postTagsByTag(t) {
    return j.match({
        type: 'Blog.Post.Tags',
        tags: [t]
    });
}

function postTitlesForPostTag(pt) {
    pt.has('post');

    return j.match({
        type: 'Blog.Post.Title',
        post: pt.post
    }).suchThat(postTitleIsCurrent);
}

function postTitleIsCurrent(t) {
    return j.notExists({
        type: 'Blog.Post.Title',
        prior: [t]
    });
}

const titles = await j.query(tag, j
    .for(postTagsByTag)
    .then(postTitlesForPostTag));

Continue With

Syntax diagram