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 go1.18beta1 and use it instead of the go command:

$ go1.18beta1 test ./...
ok  	github.com/bfollek/funcy/pkg	(cached)

Notes

Compile error, as expected, when you try something that doesn't make sense.

For example, a call to strings.ToLower on ints:

func TestMapBadFuncType(t *testing.T) {
	require := require.New(t)
	expected := []string{"bat", "cat", "hat"}
 	sl := []int{1, 2, 3, 4}
 	result := Map(sl, strings.ToLower)
 	require.Equal(expected, result)
}

gets this when you test:

# github.com/bfollek/funcy/pkg [github.com/bfollek/funcy/pkg.test]
pkg/funcy_test.go:64:20: type func(s string) string of strings.ToLower does not match inferred type func(int) T2 for func(T1) T2
FAIL	github.com/bfollek/funcy/pkg [build failed]
FAIL

Todo

  • Implement Sum on top of Reduce. That's probably a chance to use a constraint, to make sure the slice elements are addable with +.
Similar Resources

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.

Sep 1, 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

May 24, 2022

A tool to filter URLs by parameter count or size

GoFilter A tool to filter URLs by parameter count or size. This tool requires unique sorted URL list. For example: cat hosts.txt | sort -u sorted &&

Sep 10, 2021

Golang 1.18+ Generics implementation of Set methods

Golang Generics: Set A golang 1.18+ implementation of Set using Go generics Installation $ go get -u github.com/chrispappas/golang-generics-set Quick

Oct 26, 2022

Higher Order Functions using Golang Generics (Hack Days 2022)

hoff: Higher Order Functions (and Friends) Golang 1.18+ implementations of common methods/data structures using Go Generics Requirements Go 1.18 or ne

Oct 26, 2022

read copy update map for golang 1.18+

(R)ead-(C)opy-Update read copy update map for golang 1.18+ How it works This is a simple generic implementation for https://en.wikipedia.org/wiki/Read

Mar 30, 2022

Use Golang to implement PHP's common built-in functions.

PHP2Go Use Golang to implement PHP's common built-in functions. About 140+ functions have been implemented. Install go get github.com/syyongx/php2go R

Nov 25, 2022

golang implement gossip algorithm

golang implement gossip algorithm

golang implement gossip algorithm

Jan 14, 2022

Golang code-generators used to implement Kubernetes-style API types.

code-generator Golang code-generators used to implement Kubernetes-style API types. Purpose These code-generators can be used in the context of Custom

Nov 29, 2022
Related tags
Goterators - A util library that Supports aggregate & transforms functions Go. Such as filter, map, reduce, find, exist
Goterators - A util library that Supports aggregate & transforms functions Go. Such as filter, map, reduce, find, exist

Goterators Goterators is util library that Supports aggregate & transforms functions Go, including: for-each find exist reduce filter map API and func

Nov 28, 2022
Slice - provides generic Map, Reduce and Filter functions for Go.

slice slice is a simple Go package to provide generic versions of Map, Reduce and Filter on slices. I mainly wrote it as an exercise to get more famil

Sep 19, 2022
MapReduceGolang - Map Reduce with Golang

Map Reduce This demonstrates how map reduce can be run for a Synchronous path As

Sep 21, 2022
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

Nov 23, 2022
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
Functional tools in Go 1.18 using newly introduced generics

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

Oct 9, 2022
cuckoo-filter go implement. config by you 布谷鸟过滤器的Go实现,可以定制化过滤器参数

Cuckoo filter is a Bloom filter replacement for approximated set-membership queries. While Bloom filters are well-known space-efficient data structures to serve queries like "if item x is in a set?", they do not support deletion. Their variances to enable deletion (like counting Bloom filters) usually require much more space.

Nov 22, 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

Jun 30, 2022
Helpfully Functional Go like underscore.js

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

Oct 21, 2022
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" "

Apr 26, 2022