Liking cljdoc? Tell your friends :D
Clojure only.

nl.jomco.select-tree

Select subtrees of collections.

A straightforward way to describe and create subselections of nested collections.

Design Considerations

Clojury interface

Selectors should not look out of place in idiomatic clojure code; selectors are plain data.

General applicability

  • Any combination of standard clojure collections and leaf nodes can be selected
    • Vectors (x number of items from the head)
    • Maps
    • Sets
    • Lists (x number of items from the head)

Selected structure should be a "subtree" of the original

  • Selected elements in a collection remain on the same key or index; paths to items in the collection remain valid in the selection.
  • Selectors are unambiguous; the meaning of a selector does not depend on the structure of the tree.
  • Selection of a collection will return the same kind of collection.
  • Selection does not add keys to collections or extend sequential collections.
  • Selection retains metadata.

Selectors should be unambigious

  • Paths in a selection can only be specified once, to prevent ambiguity.
Select subtrees of collections.

A straightforward way to describe and create subselections of nested
collections.

# Design Considerations

## Clojury interface

Selectors should not look out of place in idiomatic clojure code;
selectors are plain data.

## General applicability

- Any combination of standard clojure collections and leaf nodes can
  be selected
  - Vectors (x number of items from the head)
  - Maps
  - Sets
  - Lists (x number of items from the head)

## Selected structure should be a "subtree" of the original

- Selected elements in a collection remain on the same key or index;
  paths to items in the collection remain valid in the selection.
- Selectors are unambiguous; the meaning of a selector does not depend
  on the structure of the tree.
- Selection of a collection will return the same kind of collection.
- Selection does not add keys to collections or extend sequential
  collections.
- Selection retains metadata.

## Selectors should be unambigious

- Paths in a selection can only be specified once, to prevent
  ambiguity.
raw docstring

select-treeclj

(select-tree coll selector)

Return a selection from coll specified by selector.

Seletors are defined recursively:

A nil selector returns coll as is.

A map selector recursively selects items in a map coll, 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).

Returns a selection of the same type as coll, with the same metadata.

Return a selection from `coll` specified by `selector`.

Seletors are defined recursively:

A `nil` selector returns coll as is.

A map selector recursively selects items in a map coll, 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).

Returns a selection of the same type as `coll`, with the same
metadata.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close