A collection of functional operators for golang with generics

test codecov

fn

fn is a collection of go functional operators with generics

Getting Started

Prerequisites

Go 1.18

go install golang.org/dl/go1.18beta1@latest
go1.18beta1 download

Installation

go get github.com/birwin93/fn

Usage

import "github.com/birwin93/fn"

func main() {
  nums := []int{1, 2, 3}
  
  sum := fn.Sum(nums)
  
  filteredNums := fn.Filter(nums, func(i int) bool {
    return i > 1
  })
  
  doubleNums := fn.Map(nums, func(i int) int {
    return i * 2
  })
  
  if fn.Contains(nums, 2) {
    fmt.Println("nums contains 2!")
  }
}

Supported Functions

Arrays / Slices

Maps

See the open issues for a full list of proposed features (and known issues).

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/newfunction)
  3. Commit your Changes (git commit -m 'Adds fn.NewFunction')
  4. Push to the Branch (git push origin feature/newfunction)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Twitter - @billy_the_kid Project Link: https://github.com/birwin93/fn

Owner
Similar Resources

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

Jan 4, 2023

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 ("

Dec 31, 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 は我々に何をも

Dec 30, 2022

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

Nov 11, 2022

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

Dec 21, 2022

Extended library functions using generics in Go.

Just few extended standard library functions for Golang using generics.

Dec 16, 2021

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(

Dec 20, 2022

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

Dec 23, 2022

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

Jan 10, 2022
Comments
  • Changes interface for fn.Last

    Changes interface for fn.Last

    Updates fn.Last to follow more idiomatic go patterns

    Before

    last, err := fn.Last(arr)
    if err == nil {
        useLast(*last)
    }
    

    Now

    last, ok := fn.Last(arr)
    if ok {
       useLast(last)  
    }
    

    This now works more like maps val, ok := someMap[key]

Related tags
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
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
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
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

Dec 14, 2022
Magma: Gives network operators an open, flexible and extendable mobile core network solution
Magma: Gives network operators an open, flexible and extendable mobile core network solution

Connecting the Next Billion People Magma is an open-source software platform tha

Dec 24, 2021
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
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
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