IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

drop

def drop[origin: ImmOrigin, IterableType: Iterable, //](ref[origin] iterable: IterableType, count: Int) -> _DropIterator[IterableType.IteratorType[False, origin_of(origin), origin]] where conforms_to(IterableType.IteratorType[False, origin_of(origin), origin].Element, Deinitable)

Creates an iterator that drops the first count elements.

This function returns an iterator that drops the first count elements from the input iterable, then yields all remaining elements.

Examples:

from std.itertools import drop

var nums = [1, 2, 3, 4, 5]
for num in drop(nums, 2):
print(num) # Prints: 3, 4, 5

Parameters:

  • origin (ImmOrigin): The origin of the iterable.
  • IterableType (Iterable): The type of the iterable.

Args:

  • iterable (IterableType): The iterable to drop elements from.
  • count (Int): The number of elements to drop.

Returns:

_DropIterator[IterableType.IteratorType[False, origin_of(origin), origin]]: An iterator that drops the first count elements.

def drop[IterableType: IterableOwned, //](var iterable: IterableType, count: Int) -> _DropIterator[IterableType.IteratorOwnedType] where conforms_to(IterableType.IteratorOwnedType.Element, Deinitable)

Creates an iterator that drops the first count elements, consuming the iterable.

Parameters:

Args:

  • iterable (IterableType): The iterable to consume and drop elements from.
  • count (Int): The number of elements to drop.

Returns:

_DropIterator[IterableType.IteratorOwnedType]: An iterator that drops the first count elements.