reformat readme

This commit is contained in:
Ruidy 2024-09-08 19:14:07 +02:00
parent eda818c6e0
commit 78b90acc67
No known key found for this signature in database
GPG key ID: E00F51288CB857CC

View file

@ -1,4 +1,4 @@
# _Underscore # \_Underscore
![License](https://img.shields.io/github/license/rjNemo/underscore?style=for-the-badge) ![License](https://img.shields.io/github/license/rjNemo/underscore?style=for-the-badge)
[![Go version](https://img.shields.io/github/go-mod/go-version/rjNemo/underscore?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/rjNemo/underscore) [![Go version](https://img.shields.io/github/go-mod/go-version/rjNemo/underscore?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/rjNemo/underscore)
@ -7,9 +7,11 @@
![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark) ![underscore](https://socialify.git.ci/rjNemo/underscore/image?description=1&font=KoHo&language=1&logo=https%3A%2F%2Fraw.githubusercontent.com%2FrjNemo%2Funderscore%2Fmain%2Fdocs%2Fstatic%2Flogo.png&owner=1&pattern=Floating%20Cogs&stargazers=1&theme=Dark)
`underscore` is a `Go` library providing useful functional programming helpers without extending any built-in objects. `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`. It is mostly a port from the `underscore.js` library based on generics brought by
`Go 1.18`.
## Usage ## Usage
@ -27,31 +29,32 @@ Please check out the [examples](examples) to see how to use the library.
package main package main
import ( import (
"fmt" "fmt"
u "github.com/rjNemo/underscore" u "github.com/rjNemo/underscore"
) )
func main() { func main() {
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
// filter even numbers from the slice // filter even numbers from the slice
evens := u.Filter(numbers, func(n int) bool { return n%2 == 0 }) evens := u.Filter(numbers, func(n int) bool { return n%2 == 0 })
// square every number in the slice // square every number in the slice
squares := u.Map(evens, func(n int) int { return n * n }) squares := u.Map(evens, func(n int) int { return n * n })
// reduce to the sum // reduce to the sum
res := u.Reduce(squares, func(n, acc int) int { return n + acc }, 0) res := u.Reduce(squares, func(n, acc int) int { return n + acc }, 0)
fmt.Println(res) // 120 fmt.Println(res) // 120
} }
``` ```
## Getting Started ## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing These instructions will get you a copy of the project up and running on your local
purposes. machine for development and testing purposes.
### Prerequisites ### Prerequisites
You need at least `go1.18` for development. The project is shipped with a [Dockerfile](Dockerfile) based on `go1.18`. You need at least `go1.18` for development. The project is shipped with a [Dockerfile](Dockerfile)
based on `go1.18`.
If you prefer local development, navigate to the [official If you prefer local development, navigate to the [official
download page](https://go.dev/dl/) and install version `1.18` or beyond. download page](https://go.dev/dl/) and install version `1.18` or beyond.
@ -92,6 +95,7 @@ make test
- `Each` - `Each`
- `Filter` - `Filter`
- `Flatmap` - `Flatmap`
- `GroupBy`
- `Find` - `Find`
- `Map` - `Map`
- `Max` - `Max`
@ -101,10 +105,11 @@ make test
### Pipe ### Pipe
Calling `NewPipe` will cause all future method calls to return wrapped values. When you've finished the computation, Calling `NewPipe` will cause all future method calls to return wrapped values. When
call `Value` to retrieve the final value. 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. Methods not returning a slice such as `Reduce`, `All`, `Any`, will break the `Chain`
and return `Value` instantly.
## Built With ## Built With
@ -112,8 +117,8 @@ Methods not returning a slice such as `Reduce`, `All`, `Any`, will break the `Ch
## Contributing ## Contributing
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct,
requests to us. and the process for submitting pull requests to us.
## Versioning ## Versioning
@ -124,13 +129,15 @@ the [tags on this repository](https://github.com/rjNemo/underscore/tags).
- **Ruidy** - _Initial work_ - [Ruidy](https://github.com/rjNemo) - **Ruidy** - _Initial work_ - [Ruidy](https://github.com/rjNemo)
See also the list of [contributors](https://github.com/rjNemo/underscore/contributors) who participated in this project. See also the list of [contributors](https://github.com/rjNemo/underscore/contributors)
who participated in this project.
## License ## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md)
file for details
## Acknowledgments ## Acknowledgments
This project is largely inspired by [Underscore.js](https://underscorejs.org/#) library. Check out the original project This project is largely inspired by [Underscore.js](https://underscorejs.org/#)
if you don't already know it. library. Check out the original project if you don't already know it.