Skip to content
This repository was archived by the owner on Aug 25, 2024. It is now read-only.
/ iter Public archive

Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

License

Notifications You must be signed in to change notification settings

mtoohey31/iter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

44a4af9 · Aug 25, 2024
Jun 13, 2022
Jun 2, 2023
Jun 4, 2023
Jun 4, 2023
Jun 12, 2022
Jun 12, 2022
Jul 27, 2023
Jul 27, 2023
Mar 31, 2022
Apr 21, 2023
Aug 25, 2024
Aug 5, 2022
Jun 2, 2023
Sep 5, 2022
Sep 5, 2022
Jun 10, 2023
Jun 4, 2023
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 17, 2022
Nov 12, 2022
Apr 21, 2023
Aug 5, 2022
Sep 17, 2022
Sep 5, 2022
Mar 16, 2022
Jun 4, 2023
Jun 4, 2023
Aug 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Jun 10, 2023
Sep 17, 2022
Sep 5, 2022
Sep 17, 2022
Aug 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Aug 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Jun 20, 2023
Sep 5, 2022
Sep 5, 2022
Sep 5, 2022
Aug 28, 2023
Sep 5, 2022

Repository files navigation

As of Go 1.23, the for ... := range ... syntax can now be used with "push-style" iterator functions. Since this package implements a different "pull-style" of iterators which are incompatible with the for ... := range ... syntax, I've decided to archive it. If you're looking for pull-style equivalents of some of the functions in this package, I'd recommend checking out the x/exp/iter package proposal.

iter

Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

Usage

package main

import (
	"fmt"
	"strings"

	"mtoohey.com/iter/v2"
)

func main() {
	initial := iter.Elems([]string{"hello", "beautiful", "world"})
	result := initial.Filter(func(s string) bool {
		return len(s) < 6
	}).Map(strings.ToUpper).Collect()
	fmt.Println(result) // produces: [HELLO WORLD]
}

Regarding Performance

There is some overhead to using the iterators in this package, since each evaluation requires a function call, so if the performance of your application is a top priority, this package might not be the best choice. Don't guess about performance though: I would recommend benchmarking to determine the impact of using iterators, because in some cases, lazy iterators may be faster than the equivalent strict loop.

Acknowledgements

About

Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

Topics

Resources

License

Stars

Watchers

Forks

Languages