Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
/ viter Public archive

Iterators for the V Programming Language

Notifications You must be signed in to change notification settings

mcastorina/viter

Repository files navigation

viter

Iterators for the V Programming Language.

Example Usage

import viter

fn main() {
	data := [1, 2, 3, 4, 5]

	out := viter.iter_int(data)
		.skip(1)
		.filter(fn (i int) bool { return i % 2 == 1 })
		.map_string(fn (i int) string { return '$i!' })
		.collect()

	println(out) // ['3!', '5!']
}

See test files for more examples.

Supported Types

Common V primitive types are supported. You cannot use this module with custom types (yet). If you would like another primitive type supported, please open an issue.

  • bool []bool
  • string []string
  • int []int
  • byte []byte
  • rune []rune
  • f64 []f64

Methods

A iter_<type> function is provided to convert an array of <type> to a viter iterator. Example: viter.iter_byte([byte(1) 3 3 7]).

If a method transforms the data, the output type should be appended to the function name (e.g. map_string).

The currently implemented methods are:

  • filter
  • map
  • skip skip_while
  • every
  • windows
  • chunks
  • rev
  • cycle
  • take take_while
  • chain chain_arr
  • count
  • collect
  • fold
  • tap debug

Speed

This module has ~60k generated lines of code, which means compilation may be noticeably slower but still less than 1s in debug mode.

This module uses lazy iterator evaluation, meaning there are no intermediate buffers. Each transformation is applied on the element as it is iterated over (or once collected).

About

Iterators for the V Programming Language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages