~jomco/select-tree

Clojure library to recursively select subtrees of collections
Version 0.1.1-SNAPSHOT
Fixup project, add linter, show namespace in readme

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~jomco/select-tree
read/write
git@git.sr.ht:~jomco/select-tree

You can also use your local clone with git send-email.

#Select Tree

Select subtrees of collections.

#Dependency coordinates

Clojars Project

#Documentation

API documentation is available inline and at cljdoc.

#USAGE

(require '[nl.jomco.select-tree :refer [select-tree]])

(def ring-request
  {:request-method :post
   :uri            "/foo"
   :headers        {"content-type"  "text/html; charset=utf8"
                    "authorisation" "Bearer SOMECREDENTIALS"}
   :body           "<html><body>Hello, World</body></html>"
   :params         {:pageNumber 1
                    :pageSize   10
                    :other      "thing"}})

(select-tree ring-request
            {:request-method nil
             :uri            nil
             :headers        #{"content-type"}
             :params         #{:pageNumber
                               :pageSize}})
=> {:request-method :post
    :uri            "/foo"
    :headers        {"content-type" "text/html; charset=utf8"}
    :params         {:pageNumber 1
                     :pageSize   10}}

#Selectors specification

nil means select whole tree

A map selector recursively selects items in a map, with selectors as values.

A set selector works as a map selector with nil values (select whole value for each key). Set selectors also work on sets.

A sequential selector of size N recursively selects the first N, or less if the collection is smaller, items in the sequential collection, with selectors as values.

An integer selector N selects the first N items in a sequential collection (like a sequential selector with N nil entries).