TuningFork.Ring (TuningFork v0.1.11)

Copy Markdown View Source

A list read round and round, so any integer index is in it.

iex> TuningFork.Ring.at([:c2, :e2, :g2], 4)
:e2

Summary

Functions

The element at index. An index past the end wraps to the start and a negative one counts back from the end. nil for an empty list.

The list turned so index is its head.

count elements from index on, wrapping.

Functions

at(list, index)

@spec at([term()], integer()) :: term() | nil

The element at index. An index past the end wraps to the start and a negative one counts back from the end. nil for an empty list.

iex> TuningFork.Ring.at([1, 2, 3], 7)
2
iex> TuningFork.Ring.at([1, 2, 3], -1)
3
iex> TuningFork.Ring.at([], 0)
nil

from(list, index)

@spec from([term()], integer()) :: [term()]

The list turned so index is its head.

iex> TuningFork.Ring.from([:a, :b, :c], 1)
[:b, :c, :a]

take(list, index, count)

@spec take([term()], integer(), non_neg_integer()) :: [term()]

count elements from index on, wrapping.

iex> TuningFork.Ring.take([:a, :b, :c], 1, 4)
[:b, :c, :a, :b]