Utilities and immutable collections for functional programming in Golang

Go-fun

Utilities and immutable collections for functional programming in Golang.

This is an experimental library to play with the new Generics Feature in Go 1.18.

Features

  • Reducers for transforming data (map, filter, group by, etc)
  • Immutable data structures
    • List
  • Mutable data structures
    • Stack
  • Iterable abstraction
  • Equality type class

Examples

Take a slice of books and return a map where the keys are authors and the values contain all the titles of the books the author has written in or after the year 2000.

= 2000 }, reducer.GroupBy(func(b Book) string { return b.Author }, reducer.Map(func(b Book) string { return b.Title }, reducer.ToSlice[string]())))) require.Equal(t, map[string][]string{ "A": {"S"}, "B": {"R", "U"}, }, m) }">
type Book struct {
	Author string
	Title  string
	Year   int
}

func TestBook(t *testing.T) {
	books := []Book{
		{"A", "Q", 1990},
		{"B", "R", 2005},
		{"A", "S", 2001},
		{"B", "T", 1999},
		{"B", "U", 2021},
	}

	m := reducer.ApplySlice(books,
		reducer.Filter(func(b Book) bool { return b.Year >= 2000 },
			reducer.GroupBy(func(b Book) string { return b.Author },
				reducer.Map(func(b Book) string { return b.Title }, reducer.ToSlice[string]()))))

	require.Equal(t, map[string][]string{
		"A": {"S"},
		"B": {"R", "U"},
	}, m)
}
Similar Resources

Go-path - A helper package that provides utilities for parsing and using ipfs paths

go-path is a helper package that provides utilities for parsing and using ipfs paths

Jan 18, 2022

A collection of small Go utilities to make life easier.

The simplego package provides a collection of Go utilities for common tasks.

Jan 4, 2023

Utilities to generate (reference) documentation for the docker CLI

About This is a library containing utilities to generate (reference) documentation for the docker CLI on docs.docker.com. Disclaimer This library is i

Dec 28, 2022

Utilities for interacting with Dockerfiles

Utilities for interacting with Dockerfiles

go-dockerfile Golang utilities for interacting with Dockerfiles. This is not a place of honor. No esteemed source code is commemorated here. Don't tak

Apr 6, 2022

Simple utilities for creating ascii text in Go

Simple utilities for creating ascii text in Go

Oct 30, 2021

golden provides utilities for golden file tests.

golden provides utilities for golden file tests.

Dec 27, 2022

Source Repo for utilities used in Atlas

Atlas-Utilities Source Repo for utilities used in Atlas filepicker Simple file picker in Go using go-common-file-dialog This returns the path of a fil

Dec 25, 2022

List-Utils - 🔧 Utilities for maintaining the list of repost sites

SMR List Utils This is a Go CLI tool that helps with managing the StopModReposts blacklist. Install Use GitHub Releases and download binary. Linux Qui

Jan 3, 2022

Utilities for processing Wikipedia dumps in Go

Utilities for processing Wikipedia dumps in Go A Go package providing utilities for processing Wikipedia dumps. Features: Supports Wikidata entities J

Nov 29, 2022
Related tags
efaceconv - Code generation tool for high performance conversion from interface{} to immutable type without allocations.

efaceconv High performance conversion from interface{} to immutable types without additional allocations This is tool for go generate and common lib (

May 14, 2022
Experimenting with golang generics to implement functional favorites like filter, map, && reduce.

funcy Experimenting with golang generics to implement functional favorites like filter, map, && reduce. 2021-12 To run the tests, you need to install

Dec 29, 2021
A collection of functional operators for golang with generics

fn fn is a collection of go functional operators with generics Getting Started P

Jul 8, 2022
Helpfully Functional Go like underscore.js

/\ \ __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ __ __

Dec 22, 2022
Make Go functional with dogs
Make Go functional with dogs

dogs Make Go functional with dogs Caution This is a highly-experimental package. Any changes will be made in a backward-incompatible manner. This pack

Jan 4, 2023
Functional tools in Go 1.18 using newly introduced generics

functools functools is a simple Go library that brings you your favourite functi

Dec 5, 2022
F - Experimenting with Go 1.18 generics to write more functional Go code

f f is a simple library that leverages the new generics in Golang to create a tools for functional style of code. Pipe like '|>' in Elixir or Elm. inp

Apr 12, 2022
CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON.

Cuetils CUE utilities and helpers for working with tree based objects in any combination of CUE, Yaml, and JSON. Using As a command line binary The cu

Dec 24, 2022
Go-Utils is a library containing a collection of Golang utilities

Go-Utils is a library containing a collection of Golang utilities

Jun 2, 2022
Utilities for rounding and truncating floating point numbers.

Rounders Provides utilities for rounding and truncating floating point numbers. Example: rounders.RoundToDecimals(12.48881, 2)

Jan 6, 2022