Files
obitools4/autodoc/docmd/pkg/obitax/iterator.md
T
Eric Coissac 8c7017a99d ⬆️ version bump to v4.5
- Update obioptions.Version from "Release 4.4.29" to "/v/ Release v5"
- Update version.txt from 4.29 → .30
(automated by Makefile)
2026-04-13 13:34:53 +02:00

32 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Semantic Description of `obitax` Package Functionalities
The `obitax` package provides a robust iterator-based API for traversing taxonomic data structures in Go. Its core component is the `ITaxon` interface, which implements a lazy, concurrent-safe iterator over taxon instances (`*Taxon`). Key features include:
- **Iterator Creation**: `ITaxon` can be instantiated via `NewITaxon()` or derived from collections:
- `TaxonSet.Iterator()`, `TaxonSlice.Iterator()` (sorted), and `Taxonomy.nodes.Iterator()`
- Goroutines feed taxa into a channel, enabling non-blocking iteration.
- **Control Methods**:
- `Next()` advances to the next taxon, returning success/failure.
- `Get()` retrieves the current taxon (must follow a successful `Next`).
- `Finished()` checks if iteration is complete.
- **Channel Management**:
- `Push(taxon)` sends a taxon into the iterators channel.
- `Close()` terminates iteration by closing the source channel.
- **Iterator Composition**:
- `Split()`: creates a new iterator sharing the same source and termination status (useful for parallel consumption).
- `Concat(...)`: merges multiple iterators sequentially into one.
- **Metadata Enrichment**:
- `AddMetadata(name, value)` wraps the iterator to inject metadata into each taxon via `SetMetadata`.
- **Subtree Traversal**:
- `ISubTaxonomy()` (on `*Taxon` or via `Taxonomy.ITaxon(taxid)`) performs a breadth-first traversal of descendant taxa, starting from the current taxon or given ID. It uses parent-child adjacency logic to expand the subtree incrementally.
- **Consumption Utility**:
- `Consume()` exhausts an iterator without processing (e.g., for side-effect-only pipelines).
All iterators are designed to be composable, memory-efficient (via channels), and safe for concurrent use. The package integrates with `obiutils` to manage pipeline registration/unregistration during subtree expansion.