No description
Find a file
2022-03-23 10:58:44 -04:00
.github last function (#17) 2022-03-21 18:04:30 +01:00
chain Code coverage (#15) 2022-03-18 18:22:01 +01:00
docs add documentation link 2022-03-23 10:58:44 -04:00
examples feat: maps map (#9) 2022-01-27 16:15:33 +01:00
maps feat: maps map (#9) 2022-01-27 16:15:33 +01:00
.dockerignore clean_builds (#14) 2022-03-18 18:16:38 +01:00
.gitignore docsite (#19) 2022-03-23 10:32:56 -04:00
.gitmodules Doc site (#5) 2021-12-31 15:37:31 +01:00
.golangci.yml feat: map 2021-12-28 19:26:42 -04:00
all.go refactor: rename Every to All 2022-01-03 11:16:01 -04:00
all_test.go refactor: rename Every to All 2022-01-03 11:16:01 -04:00
any.go refactor: rename Some to Any 2022-01-03 11:20:36 -04:00
any_test.go refactor: rename Some to Any 2022-01-03 11:20:36 -04:00
contains.go use comparable constraint in contains (#12) 2022-02-12 21:08:46 +01:00
contains_test.go chore: improve test coverage 2022-01-01 21:16:39 -04:00
CONTRIBUTING.md docs: improve README 2021-12-30 11:52:18 -04:00
Dockerfile add documentation link 2022-03-23 10:58:44 -04:00
drop.go drop (#18) 2022-03-21 18:04:38 +01:00
drop_test.go drop (#18) 2022-03-21 18:04:38 +01:00
each.go each (#10) 2022-01-28 12:51:42 -04:00
each_test.go each (#10) 2022-01-28 12:51:42 -04:00
filter.go doc: add documentation 2021-12-29 10:33:00 -04:00
filter_test.go feat: filter 2021-12-28 19:36:36 -04:00
find.go doc: find 2021-12-29 13:07:40 -04:00
find_test.go feat: find 2021-12-29 13:03:13 -04:00
go.mod Code coverage (#15) 2022-03-18 18:22:01 +01:00
go.sum Code coverage (#15) 2022-03-18 18:22:01 +01:00
last.go last function (#17) 2022-03-21 18:04:30 +01:00
last_test.go last function (#17) 2022-03-21 18:04:30 +01:00
LICENSE.md docs: improve README 2021-12-30 11:52:18 -04:00
Makefile docsite (#19) 2022-03-23 10:32:56 -04:00
map.go doc: add documentation 2021-12-29 10:33:00 -04:00
map_test.go feat: map 2021-12-28 19:26:42 -04:00
max.go Code coverage (#15) 2022-03-18 18:22:01 +01:00
max_test.go feat: max 2021-12-29 22:30:57 -04:00
min.go Code coverage (#15) 2022-03-18 18:22:01 +01:00
min_test.go chore: improve test coverage 2022-01-01 21:16:39 -04:00
partition.go feat: partition 2021-12-29 22:48:57 -04:00
partition_test.go feat: partition 2021-12-29 22:48:57 -04:00
README.md add documentation link 2022-03-23 10:58:44 -04:00
reduce.go doc: add documentation 2021-12-29 10:33:00 -04:00
reduce_test.go feat: reduce 2021-12-28 19:47:05 -04:00
result.go Add Result type (#16) 2022-03-18 18:32:41 +01:00
result_test.go Add Result type (#16) 2022-03-18 18:32:41 +01:00
sum.go Code coverage (#15) 2022-03-18 18:22:01 +01:00
sum_test.go sum (#13) 2022-02-20 15:34:09 +01:00

Underscore

License Go version test coverage

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

📚 Follow this link for the documentation.

Install the library using

go get github.com/rjNemo/underscore

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
	evens := u.Filter(numbers, func(n int) bool { return n%2 == 0 })
	// square every number in the slice
	squares := u.Map(evens, func(n int) int { return n * n })
	// reduce to the sum
	res := u.Reduce(squares, func(n, acc int) int { return n + acc }, 0)

	fmt.Println(res) // 120
}

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

To run the unit tests, you can simply run:

make test

Functions

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

Collections

  • All
  • Any
  • Contains (only numerics values at the moment)
  • Each
  • Filter
  • Find
  • Map
  • Max
  • Min
  • Partition
  • Reduce

Chaining

Calling chain.Of will cause all future method calls to return wrapped values. When you've finished the computation, call Value to retrieve the final value.

Methods not returning a slice such as Reduce, All, Any, will break the Chain and return Value instantly.

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.