arriterator

package module
v0.0.0-...-c318be4 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 2 Imported by: 0

README

arriterator

A simple iterator for Go array/slice

Usage

package main

import (
  arr "github.com/Asphaltt/arriterator"
  "fmt"
)

func main() {
  i, e := arr.New([]int{111, 222, 333})
  if e != nil {
    panic(e)
  }
  
  for i.HasNext() {
    fmt.Println(i.Next())
  }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator interface {
	// HasNext gets whether the iterator has next element
	HasNext() bool

	// Next gets the next elements of the iterator
	Next() interface{}
}

Iterator is the interface of `arriterator`

func New

func New(val interface{}) (Iterator, error)

New creates an iterator from `val`. If `val` is `nil` or is neither array nor slice, you won't get an iterator and will get an error.

The created iterator converts `val` to `arr` of `[]interface{}`, and keeps its own index `idx` for iterating, and keeps the size `size` of `arr`.

Jump to

Keyboard shortcuts

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