/fn

A collection of functional operators for golang with generics

Primary LanguageGoMIT LicenseMIT

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.181@latest
go1.18 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