F - Experimenting with Go 1.18 generics to write more functional Go code

Related tags

Utilities f
Overview

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.

input := 1
add1 := func(i int) int { return i + 1 }
mul2 := func(i int) int { return i * 2 }
f.Pipe(input, add1, mul2) // 4

Collections

Map

f.Map(func(elem int) int { return elem * 2 }, []int{2, 3, 4, 5}) // [4, 6, 8, 10]

Reduce

f.Reduce(0, func(a, b int) int { return a + b }, []int{1, 2, 3, 4, 5, 6}) // 21

Filter

f.Filter(func(elem int) bool { return elem%2 == 0 }, []int{1, 2, 3, 4, 5, 6}) // [2, 4, 6]

Nth

f.Nth([]int{1, 2, 3, 4, 5}, 2) // 3

Take

f.Take([]int{1, 2, 3, 4, 5}, 2)) // [1, 2]

TakeLast

f.TakeLast([]int{1, 2, 3, 4, 5}, 2)) // [4, 5]

Remove

f.Remove([]int{3, 4, 5}, 0)) // [4, 5]

Head

f.Head([]int{3, 4, 5})) // 3

Tail

f.Tail([]int{3, 4, 5})) // [4, 5]
You might also like...
Package truthy provides truthy condition testing with Go generics
Package truthy provides truthy condition testing with Go generics

Truthy Truthy is a package which uses generics (Go 1.18+) to create useful boolean tests and helper functions. Examples // truthy.Value returns the tr

Go Library for Competitive Programming with Generics

Go Library for Competitive Programming with Generics Go used to be a difficult language to use for competitive programming. However, with the introduc

Extended library functions using generics in Go.

Just few extended standard library functions for Golang using generics.

A library that provides Go Generics friendly "optional" features.

go-optional A library that provides Go Generics friendly "optional" features. Synopsis some := optional.Some[int](123) fmt.Printf("%v\n", some.IsSome(

experimental promises in go1.18 with generics

async go a prototype of "promises" in go1.18. note: this is just an experiment used to test alternate patterns for dealing with asynchronous code in g

Go 1.18 generics use cases and examples

Go 1.18 generics use cases What are generics? See Type Parameters Proposal. How to run the examples? As of today, gotip is the simplest way to run the

Benchmarks to compare Go Generics

This is a collection of various sorts implemnted both as []int only and as const

Utility library that uses Go generics mechanism

golang-generics-util Utility library that explores Go generics (1.18) xsync Sync

CDN-like in-memory cache with shielding, and Go 1.18 Generics

cache CDN-like, middleware memory cache for Go applications with integrated shielding and Go 1.18 Generics. Usage package main import ( "context" "

Owner
Amirreza Askarpour
Software Enginner, #gopher
Amirreza Askarpour
Code Generation for Functional Programming, Concurrency and Generics in Golang

goderive goderive derives mundane golang functions that you do not want to maintain and keeps them up to date. It does this by parsing your go code fo

Walter Schulze 1.1k Dec 25, 2022
Functional tools in Go 1.18 using newly introduced generics

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

Rakeeb Hossain 173 Dec 5, 2022
A collection of functional operators for golang with generics

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

Billy Irwin 9 Jul 8, 2022
Go-generics-simple-doubly-linked-list - A simple doubly linked list implemented using generics (Golang)

Welcome to Go-Generics-Simple-Doubly-Linked-List! Hi, This repository contains a

Behrad Ravanbod 5 Jun 30, 2022
Example code for Go generics

go-generics-example Example code for Go generics. Usage $ go build -gcflags=-G=3 Requirements Go 1.17 or later Advertise Go 言語にやってくる Generics は我々に何をも

mattn 1.3k Dec 30, 2022
Helpfully Functional Go like underscore.js

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

null 385 Dec 22, 2022
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

Genta Kamitani 37 Jan 4, 2023
Utilities and immutable collections for functional programming in Golang

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.

Peter Zeller 9 Sep 1, 2022
Experiments with Go generics

generics Quick experiments with Go generics algebra, a generic square root function for float, complex and and rational. future, a concurrent cache ("

Alan Donovan 84 Dec 31, 2022
Collection of unusual generics usecases in Go

Unusual Generics Type parameters or Generics in Go designed to reduce boilerplate for container data types like lists, graphs, etc. and functions like

Vladimir Stolyarov 54 Dec 14, 2022