ham-fisted.iterator

Generialized efficient pathways involving iterators.

->iterator

(->iterator item)

Convert a stream, supplier, or an iterable into an iterator.

ary-iter

(ary-iter ary-data)

Create an iterator for any primitive or object java array.

blocking-queue->iterable

(blocking-queue->iterable queue term-symbol)(blocking-queue->iterable queue timeout-us timeout-symbol term-symbol)

Given a blocking queue return an iterable that iterates until queue returns term-symbol. Uses take to block indefinitely -- will throw any throwable that comes out of the queue.

const-iterable

(const-iterable arg)

Return an iterable that always returns a arg.

current-iterator

(current-iterator item)

Return a current iterator - and iterator that retains the current object. This iterator is positioned just before the first object so it's current item is nil.

doiter

macro

(doiter varname iterable & body)

Execute body for every item in the iterable. Expecting side effects, returns nil.

has-next?

(has-next? iter)

Given an iterator or nil return true if the iterator has next.

iter-cons

(iter-cons vv iter)

Produce a new iterator that points to vv then defers to passed in iterator.

iterable

(iterable valid? init-fn update-fn val-fn)(iterable init-fn update-fn)

Create an iterable. init-fn is not called until the first has-next call.

  • valid? - ctx->boolean - defaults to non-nil?
  • init-fn - creates new ctx
  • update-fn - function from ctx->ctx
  • val-fn - function from ctx->val - defaults to deref

linear-merge-iterator

(linear-merge-iterator cmp p iterators)(linear-merge-iterator cmp iterators)(linear-merge-iterator iterators)

Create a merging iterator - fast for N < 8.

maybe-next

(maybe-next iter)

Given an iterator or nil return the next element if the iterator hasNext.

merge-iterable

(merge-iterable cmp iterables)

Create an efficient n-way merge between a sequence of iterables using comparator. If iterables themselves are sorted result will be sorted.

non-nil?

(non-nil? a)

once-iterable

(once-iterable valid? init-fn update-fn val-fn)(once-iterable valid? init-fn)(once-iterable init-fn)

Create an iterable that can only be iterated once - it always returns the same (non threadsafe) iterator every iterator call. init-fn is not called until the first has-next call - also see iterable.

The arguments have different defaults as once-iterables can close over global context on construction as they can only be iterated once.

  • valid? - ctx->boolean - defaults to non-nil?
  • init-fn - creates new ctx
  • update-fn - function from ctx->ctx - defaults to init-fn ignoring argument.
  • val-fn - function from ctx->val - defaults to identity

seq-iterable

(seq-iterable iterable)

Iterable with efficient reduce but also contains a cached seq conversion so patterns like: (when (seq v) ...) still work without needing to dereference the iterable twice.