Skip to content

Sleepyowl/oriju

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#OriJu

##What's that?

It's reduce() for binary or 'normal' trees.

##What do one use that for?

It's intended to be used to traverse and transform trees in a functional fashion as an alternative to visitor pattern and such.

##Example?

import {Tree} from "oriju";

// filter in the format of a popular UI library
const filter = {
    logic: "and",
    filters: [
        {
            logic: "or",
            filters: [
                {
                    operator: "eq",
                    field: "position",
                    value: "QA Engineer"
                },
                {
                    operator: "eq",
                    field: "position",
                    value: "UX Engineer"
                }
            ]
        },
        {
            operator: "eq",
            field: "age",
            value: "20"
        }
    ]
};

// translating it to elasticsearch QueryDSL
Tree.from(filter, "filters").fold(
        (acc, node)=>({
            bool: {
                [node.logic == "or" ? "should" : "must"]: acc
            }}), 
        (leaf)=>({
            // for simplicity, assuming operator to be always "eq"
            term: {[leaf.field]: leaf.value}
        })
);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published