A library providing useful functional programming helpers for Go 1.18

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

Owner
Ruidy
Senior Full Stack Engineer
Ruidy
Similar Resources

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

Jan 21, 2022

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

Jan 19, 2022

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

Nov 28, 2021

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

Oct 18, 2022

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

Nov 9, 2021

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

Nov 6, 2022

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

Oct 22, 2022

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

Dec 15, 2021

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

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

  • 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.

  • [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)
    }
    
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

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

Jan 9, 2023
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

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.

Jan 2, 2023
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

Jul 28, 2022
Crash Course about the programming language Go / Golang.
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.

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

Jan 1, 2023
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

Aug 27, 2022
An open source programming language that makes it easy to build simple
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

Oct 15, 2021
Programming Paradigm With Golang
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

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

Oct 21, 2021