go-functional

module
v2.0.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT

README

Functional Programming in Go

GitHub release (with filter) Actions Status Go Reference Go Report Card codecov

A library of iterators for use with iter.Seq. Requires Go 1.23+.

// The first 5 natural numbers
numbers := slices.Collect(
	it.Take(it.Count[int](), 5),
)

// All even numbers
evens := it.Filter(it.Count[int](), filter.IsEven)

// String representations of integers
numbers := it.Map(it.Count[int](), strconv.Itoa)

Read the docs to see the full iterator library.

Installation

go get github.com/BooleanCat/go-functional/v2@latest

Iterator Chaining

The iterators in this package were designed to be used with the native iter.Seq from Go's standard library. In order to facilitate complex sequences of iterators, the itx package provides Iterator and Iterator2 as wrappers around iter.Seq and iter.Seq2 that allow for chaining operations.

Let's take a look at an example:

// The first 10 odd integers
itx.Count[int]().Filter(filter.IsOdd).Take(10).Collect()

Most iterators support chaining. A notable exception is it.Map which cannot support chaining due to limitations on Go's type system.

Directories

Path Synopsis
internal
it
filter
This package contains functions intended for use with [iter.Filter].
This package contains functions intended for use with [iter.Filter].
itx
op

Jump to

Keyboard shortcuts

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