Skip to content

Commit

Permalink
Merge pull request #14 from hatena/readme-usage
Browse files Browse the repository at this point in the history
Update README.md with details on setup; fix flaky tests
  • Loading branch information
stefafafan authored Sep 24, 2023
2 parents 4032dc3 + 30456e3 commit 1d4a287
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,78 @@ https://github.com/samber/lo is a nice library, but in some cases teams do not w
hatena/godash is meant to only provide a small portion of samber/lo's functions:
- functions that are not available via Go's standard library
- functions that are not "too much", such as "Conditional helpers" or "Error handling"

## Usage
Install the package to your repo with `go get`.

```sh
go get -u github.com/hatena/godash
```

Sample usage:
```go
package main

import (
"fmt"

"github.com/hatena/godash"
)

func main() {
integers := []int{0, 1, 1, 3, 2, 1, 1, 0}
fmt.Println(godash.Chunk(integers, 3))
}
```

Check out more examples at [godash package - github.com/hatena/godash - Go Packages](https://pkg.go.dev/github.com/hatena/godash).

### Recommended golangci-lint configuration
Since this package aims to only present a subset of functions from `samber/lo`, it is recommended to add linter settings to deny importing directly from `samber/lo`. (If you want to use `samber/lo` directly, then there is no meaning to use `hatena/godash`).

Below is a minimal `.golangci.yml` configuration to deny `samber/lo` imports.

```yml
linters:
enable:
- depguard

linters-settings:
depguard:
rules:
deny-samber-lo:
deny:
- pkg: "github.com/samber/lo"
desc: Use github.com/hatena/godash instead.
```
Once you have `.golangci.yml`, make sure to run `golangci-lint` via CI. Below is an example for GitHub Actions.

```yml
name: CI
on:
push:
branches: main
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: "go.mod"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
only-new-issues: true
```

See [Introduction | golangci-lint](https://golangci-lint.run/) for more details.
11 changes: 8 additions & 3 deletions godash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godash_test

import (
"fmt"
"slices"

"github.com/hatena/godash"
)
Expand Down Expand Up @@ -130,7 +131,9 @@ func ExampleKeys() {
2: "bar",
3: "baz",
}
fmt.Println(godash.Keys(m))
keys := godash.Keys(m)
slices.Sort(keys)
fmt.Println(keys)
// Output: [1 2 3]
}

Expand All @@ -140,8 +143,10 @@ func ExampleValues() {
2: "bar",
3: "baz",
}
fmt.Println(godash.Values(m))
// Output: [foo bar baz]
values := godash.Values(m)
slices.Sort(values)
fmt.Println(values)
// Output: [bar baz foo]
}

func ExampleSum() {
Expand Down

0 comments on commit 1d4a287

Please sign in to comment.