iterator

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2023 License: MIT Imports: 0 Imported by: 0

README

iterator

Install

You can install the package as below:

go get github.com/gozeloglu/iterator

Usage

Firstly, you need to create an iter object with New function. You can pass elements to that function.

it := iterator.New(1,2,3,4)

Then, you can call the methods by using it object.

package main

import "github.com/gozeloglu/iterator"

func main() {
	it := iterator.New(1,2,3,4)
	it.Next()   // Retrieve next element if exists
	it.HasNext()    // Check whether there is element in next
	it.Prev()   // Retrieve previous element if exists
	it.HasPrev()    // Check whether there is element in previous
	it.ToSlice()    // Retrieve all elements in slice
}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iter

type Iter struct {
	// contains filtered or unexported fields
}

Iter keeps data and index.

func New

func New(a ...any) *Iter

New creates *Iter object by given elements in parameter. If nothing is passed it creates an empty slice.

func (*Iter) HasNext

func (i *Iter) HasNext() bool

HasNext returns whether iter has element in next.

func (*Iter) HasPrev

func (i *Iter) HasPrev() bool

HasPrev returns whether iter has element in previous.

func (*Iter) Next

func (i *Iter) Next() any

Next returns the next element. If there is no next element, it returns nil.

func (*Iter) Prev

func (i *Iter) Prev() any

Prev returns previous element. If there is no previous element, it returns nil.

func (*Iter) ToSlice

func (i *Iter) ToSlice() []any

ToSlice returns data.

type Iterator

type Iterator interface {
	HasNext() bool
	HasPrev() bool
	Next() any
	Prev() any
	ToSlice() []any
}

Iterator interface contains the iterator functions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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