A library providing useful functional programming helpers for Go 1.18

Overview

Underscore

License Go version

underscore

underscore is a Go library providing useful functional programming helpers without extending any built-in objects.

It is mostly a port from the underscore.js library based on generics brought by go1.18.

Usage

Please check out the examples to see how to use the library.

package main

import (
	"fmt"
	u "github.com/rjNemo/underscore"
)

func main() {
	numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	// filter even numbers from the slice
	isEven := func(n int) bool { return n%2 == 0 }
	evens := u.Filter(numbers, isEven)
	// square every number in the slice
	toSquare := func(n int) int { return n * n }
	squares := u.Map(evens, toSquare)
	// reduce to the sum 
	sum := func(n, acc int) int { return n + acc }
	res := u.Reduce(squares, sum, 0)

	fmt.Println(res) // 110
}

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

You need at least go1.18 for development. The project is shipped with a Dockerfile based on go1.18. If you prefer local development, at the moment the easiest way to do it:

go install golang.org/dl/[email protected]
go1.18beta1 download

Installing

First clone the repository

git clone https://github.com/rjNemo/underscore.git

Install dependencies

go mod download

And that's it.

Tests

Building the docker image will run the tests automatically. Otherwise, you can simply run:

go test ./...

Functions

underscore provides 100s of functions that support your favorite functional helpers

Collections

  • map
  • filter
  • reduce
  • each
  • some
  • every
  • find
  • contains (only numerics values at the moment)
  • max
  • min
  • partition

Built With

  • Go - Build fast, reliable, and efficient software at scale

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Ruidy - Initial work - Ruidy

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

This project is largely inspired by Underscore.js library. Check out the original project if you don't already know it.

You might also like...
I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute.
I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute.

Go-language I will be uploading some basic programming in Golang so if you want to contribute please Fork this repo and contriute. This repo is for pr

Web programming tutorial with Golang

Tutorial de programação Web com Golang Para rodar o servidor Entre na pasta web_app, onde está o main.go cd caminho/para/pasta/web_app Agora execute

Repository for COMP 429 Programming Assignment# 1 - A simple chat application, by Sabra Bilodeau.

Chatty COMP 429 Programming Assignment 1 A Chat Application for Remote Message Exchange by Sabra Bilodeau Getting Started with Chatty Building the Pro

Solving structy.net data structures & algorithms programming problems in Go (with Tests)

structy.net Solving structy.net data structures & algorithms programming problems in Go (with Tests) I. Introduction 000. hey programmer 001. max-valu

A programming job interview question problem

Unscramble a scrambled URL Problem statement The problem statement follows. I copied it literally because there's no good way to summarize and retain

A repository for showcasing my knowledge of the Google Go (2009) programming language, and continuing to learn the language.

Learning Google Golang (programming language) Not to be confused with the Go! programming language by Francis McCabe I don't know very much about the

A repository for showcasing my knowledge of the Go! (2003) programming language, and continuing to learn the language.
A repository for showcasing my knowledge of the Go! (2003) programming language, and continuing to learn the language.

Learning Go! (programming language) Not to be confused with Google Golang (2009) I don't know too much about the Go! programming language, but I know

Repo Tugas Basic Programming Part 2(Input/Output, Branching, Looping) ALTA Immersive BE5

Cara mengerjakan tugas hari ke 2 clone project ini dengan cara git clone https://github.com/jackthepanda96/Intro-to-Algoritm-Part2.git setelah clone

Repo Tugas Basic Programming Part 4(Complexity Analysis, Array, Slice, Function) ALTA Immersive BE5

Cara mengerjakan tugas hari ke 4 clone project ini dengan cara git clone https://github.com/ALTA-Immersive-BE5/Basic-Programming-Part4.git setelah cl

Comments
  • Adding some new funky functions

    Adding some new funky functions

    Created the Join, JoinProjection, Range, SumMap, Zip functions, each function is documented with how it works and has a unit test or maybe more

    Created a Tuple struct as some of the new functions require you to return a new slice with two fields which is the result of the new functions, i.e. Join and Zip

    enhancement 
    opened by theouteredge 2
  • Contains should require comparable, not constraints.Ordered

    Contains should require comparable, not constraints.Ordered

    As stated in the title, Contains should require the type to be comparable and not constraints.Ordered, as it add useless type limitation.

    For example this function is not usable with string.

    enhancement 
    opened by Ludonope 1
  • Contributors link is broken

    Contributors link is broken

    In README.md the line See also the list of contributors who participated in this project. should redirect to the project's contributors page but not currently.

    bug 
    opened by rjNemo 0
  • [FEATURE] Each with multiple args

    [FEATURE] Each with multiple args

    would you accept tests helpers on this repo ?

    like parametrize ?

    func parametrize[V any, T any](fn T, allValues [][]V) {
        v := reflect.ValueOf(fn)
        for _, a := range allValues {
            vargs := make([]reflect.Value, len(a))
    
            for i, b := range a {
                vargs[i] = reflect.ValueOf(b)
            }
            v.Call(vargs)
        }
    }
    
    func tutu(a int) int {
        return a + 1
    }
    
    func Test_tutu(t *testing.T) {
        testsArgs := [][]any{
            {t, 1, 2}, {t, 3, 4},
        }
        test := func(t *testing.T, input int, expected int) {
            assert.Equal(t, tutu(input), expected)
        }
        parametrize(test, testsArgs)
    }
    
    enhancement 
    opened by raphaelauv 2
Releases(v0.5.0)
  • v0.5.0(Sep 4, 2022)

    What's Changed

    • add flatmap by @rjNemo in https://github.com/rjNemo/underscore/pull/31
    • Adding some new funky functions by @theouteredge in https://github.com/rjNemo/underscore/pull/32

    New Contributors

    • @theouteredge made their first contribution in https://github.com/rjNemo/underscore/pull/32

    Full Changelog: https://github.com/rjNemo/underscore/compare/v0.4.0...v0.5.0

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Mar 23, 2022)

    What's Changed

    • add unit test pipeline by @rjNemo in https://github.com/rjNemo/underscore/pull/8
    • feat: maps map by @rjNemo in https://github.com/rjNemo/underscore/pull/9
    • each by @rjNemo in https://github.com/rjNemo/underscore/pull/10
    • use comparable constraint in contains by @rjNemo in https://github.com/rjNemo/underscore/pull/12
    • :sparkles: sum by @rjNemo in https://github.com/rjNemo/underscore/pull/13
    • clean build files by @rjNemo in https://github.com/rjNemo/underscore/pull/14
    • Code coverage by @rjNemo in https://github.com/rjNemo/underscore/pull/15
    • Add Result type by @rjNemo in https://github.com/rjNemo/underscore/pull/16
    • last function by @rjNemo in https://github.com/rjNemo/underscore/pull/17
    • drop by @rjNemo in https://github.com/rjNemo/underscore/pull/18
    • docsite by @rjNemo in https://github.com/rjNemo/underscore/pull/19

    Full Changelog: https://github.com/rjNemo/underscore/compare/v0.3.0...0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Dec 30, 2021)

Owner
Ruidy
Senior Full Stack Engineer
Ruidy
An experimental generic functional utility library inspired by Lodash

go-godash An experimental generic functional utility library inspired by Lodash Implemented functions Map Reduce Sum Filter Take TakeWhile Drop DropWh

Stewart Platt 6 May 31, 2022
Go programming language secure coding practices guide

You can download this book in the following formats: PDF, Mobi and ePub. Introduction Go Language - Web Application Secure Coding Practices is a guide

OWASP 4.3k Nov 20, 2022
The Little Go Book is a free introduction to Google's Go programming language

The Little Go Book is a free introduction to Google's Go programming language. It's aimed at developers who might not be quite comfortable with the idea of pointers and static typing. It's longer than the other Little books, but hopefully still captures that little feeling.

Dariush Abbasi 13.3k Nov 22, 2022
Some examples for the programming language Go.

Golang_Examples Bubblesort: simple implementation of bubble sort algorithm in Go Level: Beginner GenericStack: a stack (LIFO collection) that can hold

Ulrich Schramme 14 Jul 28, 2022
Crash Course about the programming language Go / Golang.

Crash Course about the programming language Go / Golang. In this course I have covered some important concepts and topics in programming.

Gabriel Dimitrievski 99 Oct 10, 2022
A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb

Golang series A complete guide to undersatnd golang programming language, web requests, JSON and creating web APIs with mongodb LearnCodeonline.in 01

HItesh Choudhary 88 Nov 20, 2022
go programming language tutorial

go programming language tutorial Hello World Hello World fmt package Variables Short Declaration The Var Keyword Exploring Type Own Type Conversion Ty

Sajjad Manafi 9 Aug 27, 2022
An open source programming language that makes it easy to build simple

The Go Programming Language Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Gopher ima

null 0 Oct 15, 2021
Programming Paradigm With Golang

Programming-Paradigm After running python3 1_22.py you'll get a prompt: which, after entering start and the end of the interval, should create next wi

null 0 Oct 16, 2021
A practical journey into the Golang Programming Language

OneTutorial - A practical journey into the Golang Programming Language This little project will help you touch many topics around Golang, in a small a

Rogério Araújo 2 Oct 21, 2021