No description
Find a file
2024-11-21 05:19:03 +01:00
.github update codecov action version 2024-11-01 10:13:44 +01:00
docs format docs 2024-09-08 19:11:52 +02:00
examples Pipe (#26) 2022-03-31 17:37:02 +02:00
maps feat: maps map (#9) 2022-01-27 16:15:33 +01:00
.dockerignore Pipe (#26) 2022-03-31 17:37:02 +02:00
.gitignore Adding some new funky functions (#32) 2022-09-04 09:21:31 +02: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
count.go Updating Count function (#36) 2023-06-13 14:21:56 +02:00
count_test.go Updating Count function (#36) 2023-06-13 14:21:56 +02:00
difference.go U 21 diff (#23) 2022-03-24 17:30:01 +01:00
difference_test.go U 21 diff (#23) 2022-03-24 17:30:01 +01:00
Dockerfile update to go 1.23 2024-09-08 19:39:27 +02:00
Dockerfile.doc add dockerfile to build doc 2024-09-08 20:12:47 +02: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 Pipe (#26) 2022-03-31 17:37:02 +02: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
flatmap.go add flatmap (#31) 2022-08-10 17:01:43 +02:00
flatmap_test.go add flatmap (#31) 2022-08-10 17:01:43 +02:00
go.mod update to go 1.23 2024-09-08 19:39:27 +02:00
go.sum update to go 1.23 2024-09-08 19:39:27 +02:00
groupby.go add groupBy function (#28) 2022-04-20 22:23:59 +02:00
groupby_test.go add groupBy function (#28) 2022-04-20 22:23:59 +02:00
intersection.go add intersection (#25) 2022-03-27 06:34:09 +02:00
intersection_test.go add intersection (#25) 2022-03-27 06:34:09 +02:00
join.go minor documentation fixes 2024-11-21 05:19:03 +01:00
join_test.go Adding some new funky functions (#32) 2022-09-04 09:21:31 +02: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 add group by to docs 2023-06-07 14:49:55 +02: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
orderBy.go minor documentation fixes 2024-11-21 05:19:03 +01:00
orderBy_test.go Adding some new funky functions (#32) 2022-09-04 09:21:31 +02: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
pipe.go Pipe (#26) 2022-03-31 17:37:02 +02:00
pipe_test.go Pipe (#26) 2022-03-31 17:37:02 +02:00
pointers.go minor documentation fixes 2024-11-21 05:19:03 +01:00
pointers_test.go adding support for quick pointer conversion (#38) 2024-11-01 10:24:53 +01:00
range.go minor documentation fixes 2024-11-21 05:19:03 +01:00
range_test.go Adding some new funky functions (#32) 2022-09-04 09:21:31 +02:00
README.md reformat readme 2024-09-08 19:14:07 +02: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
slices.go minor documentation fixes 2024-11-21 05:19:03 +01:00
slices_test.go Adding support for Slice sorting (Asc & Desc) (#37) 2024-11-01 10:18:33 +01:00
sum.go minor documentation fixes 2024-11-21 05:19:03 +01:00
sum_test.go Adding some new funky functions (#32) 2022-09-04 09:21:31 +02:00
ternary.go minor documentation fixes 2024-11-21 05:19:03 +01:00
ternary_test.go ternary op function (#29) 2022-06-08 09:14:03 +02:00
tuple.go minor documentation fixes 2024-11-21 05:19:03 +01:00
unique.go minor documentation fixes 2024-11-21 05:19:03 +01:00
unique_test.go unique function (#27) 2022-04-12 23:32:13 +02:00
zip.go minor documentation fixes 2024-11-21 05:19:03 +01:00
zip_test.go Adding some new funky functions (#32) 2022-09-04 09:21:31 +02:00

_Underscore

License Go version Go report 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 Go 1.18.

Usage

📚 Follow this link for the documentation.

Install the library using

go get github.com/rjNemo/underscore@0.4.0

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, navigate to the official download page and install version 1.18 or beyond.

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 many of functions that support your favorite functional helpers

Collections

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

Pipe

Calling NewPipe 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.