Skip to content

Commit

Permalink
update readme && fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Artjoms Suharevs committed Jan 12, 2023
1 parent 0398d27 commit 98b3b5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This library make suse of go generics, a.k.a type parameters with `Option` patte
## Dict
List of functions for go `map`
```go
package main

import "github.com/imunhatep/gocollection/dict"

func Keys[K comparable, V any](data map[K]V) []K {}
func Values[K comparable, V any](data map[K]V) []V {}
func Copy[K comparable, V any](data map[K]V) map[K]V {}
Expand Down Expand Up @@ -66,16 +70,55 @@ func UniqueAny[V any](data []V) []V {}
## Examples
More examples could be found in go tests

Dict
```go
func NewStrTestMap(size int) HashMap[string, string] {
values := map[string]string{}
for _, i := range helper.Range(1, size) {
values[fmt.Sprintf("key_%d", i)] = fmt.Sprintf("value_%d", i)
}
package main

import "github.com/imunhatep/gocollection/dict"

func NewIntTestMap(size int) map[string]int {
values := map[string]int{}
for _, i := range helper.Range(1, size) {
values[fmt.Sprintf("key_%d", i)] = i
}

return values
}

return ToMap(values)
func main() {
double := func(i string, p int) int { return p * 2 }
// map
l1 := NewIntTestMap(5)
r1 := dict.Map(l1, double)
}
```

Slice
```go
package main

import "github.com/imunhatep/gocollection/slice"

l1 := NewStrTestMap(5)
l2 := l1.Remove(l1.Keys().Head().MustGet())
func main() {
stringify := func(p int) string { return string(rune(p * 2)) }

// map
l1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
r1 := slice.Map(l1, stringify)
}
```

Sequence struct:
```go
package main

import "github.com/imunhatep/gocollection/immutable"

func main() {
double := func(p int) string { return string(rune(p * 2)) }

// map
l1 := immutable.NewSequence([]int{1, 2, 3, 4, 5, 6, 7, 8, 9}...)
r1 := l1.Map(double).Head().OrElse(0)
}
```
2 changes: 1 addition & 1 deletion build/test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ ENV GOARCH=amd64
ADD . /project/
WORKDIR /project/

RUN go test -v -coverprofile=coverage.out ./gocollection/... \
RUN go test -v -coverprofile=coverage.out ./... \
&& go tool cover -func=coverage.out

0 comments on commit 98b3b5c

Please sign in to comment.