iterator

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 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()   // Check whether there is element in next
	it.Value()  // Retrieve next element if exists
	it.Prev()   // Check whether there is element in prev
	it.ToSlice()    // Retrieve all elements in slice
	it.First()  // Updates the cursor by moving first index
	it.Last()   // Updates the cursor by moving last index
}

Running tests

You can run the test with following command.

go test
go test -v  # verbose output

You can also get code coverage with the following command.

go test -cover
go test -cover -v # verbose output

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) First added in v1.0.0

func (i *Iter) First()

First updates the cursor by moving to first index.

func (*Iter) Last added in v1.0.0

func (i *Iter) Last()

Last updates the cursor by moving to last index. If array is empty, the cursor will be zero.

func (*Iter) Next

func (i *Iter) Next() bool

Next returns whether iter has element in next. If there is no next element, it returns false.

func (*Iter) Prev

func (i *Iter) Prev() bool

Prev returns whether iter has element in prev. If there is no previous element, it returns false.

func (*Iter) ToSlice

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

ToSlice returns data.

func (*Iter) Value added in v1.0.0

func (i *Iter) Value() any

Value returns current value. If there is no value, it returns nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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