collections

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 3 Imported by: 3

README

Hannibal / collections

This package provides channel-based tools for traversing ActivityStreams collections.

// Retrieve a collection from the interwebs
outboxCollection := streams.NewDocument("https://your-website/@your-actor/outbox")

// Create a channel to iterate over the collection
documentChannel := collections.Documents(outboxCollection, context.TODO().Done())

// Yep. That's all there is. Now get to work.
for document := range documentChannel {
	// do stuff.
}
Traversing All Documents in a Collection

The Documents() function is probably the only function you'll need from this package. It returns a channel of all documents in a collection. It works with both Collections, and OrderedCollections, regardless of whether all documents are included directly in the collection, or if they are spread across multiple pages.

Traversing All Pages in a Collection

The Pages function returns a channel of all pages in a collection. It can traverse both CollectionPages and OrderedCollectionPages

Additional Tools

The rosetta channel package includes a number of functions for manipulating channels. For instance, if you don't want to read an actor's entire outbox, you might limit the results like this:

// Retrieve a collection from the interwebs
outboxCollection := streams.NewDocument("https://your-website/@your-actor/outbox")

// Create a "done" channel to cancel iterating over the collection
var done chan struct{}

// Create a channel to iterate over the collection
documentChannel := collections.Documents(outboxCollection, done)

// Limit will use the "done" channel to cancel iteration once we reach the limit
limitedChannel := channel.Limit(10, documentChannel, done)

// Now just iterate.  The limitedChannel will close after 10 documents.
for document := range limtedChannel {
	// do stuff.
}

Documentation

Overview

Package iterator provides utilities for iterating through remote collections (represented as streams.Documents)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Documents

func Documents(collection streams.Document, done <-chan struct{}) <-chan streams.Document

func NewIterator added in v0.8.0

func NewIterator(collection streams.Document, options ...IteratorOption) <-chan streams.Document

NewIterator is API-sugar for collections.Documents() iterator.

func Pages

func Pages(collection streams.Document, done <-chan struct{}) <-chan streams.Document

Types

type IteratorOption added in v0.8.0

type IteratorOption func(channel <-chan streams.Document, done chan struct{}) <-chan streams.Document

func WithLimit added in v0.8.0

func WithLimit(depth int) IteratorOption

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL