From f2d8c593f624c7eb9b3dd4705abc7e65303e8e26 Mon Sep 17 00:00:00 2001 From: Linneeeeeeee Date: Tue, 5 Sep 2023 15:33:10 +1000 Subject: [PATCH] Dev (#25) * Dev --- .github/workflows/check.yml | 32 --------- .github/workflows/lint.yml | 20 ------ .github/workflows/pull_request.yml | 25 ++++++- .github/workflows/release.yml | 24 +++---- .github/workflows/test.yml | 29 --------- README.md | 101 +++++++++++++++++++++-------- 6 files changed, 107 insertions(+), 124 deletions(-) delete mode 100644 .github/workflows/check.yml delete mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index 5da5dbc..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: check - -on: - push: - branches-ignore: - - main - workflow_dispatch: - -permissions: - contents: read - -jobs: - main: - defaults: - run: - shell: bash - permissions: - contents: read - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - check-latest: true - - run: go install golang.org/x/lint/golint@latest - - run: golint -set_exit_status ./... diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 91c1024..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: lint - -on: - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - lint: - defaults: - run: - shell: bash - permissions: - contents: read - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 0a0ca2a..9ec0734 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -2,12 +2,25 @@ name: pull_request on: pull_request: - branches: - - main workflow_dispatch: jobs: - main: + + lint: + defaults: + run: + shell: bash + permissions: + contents: read + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + - uses: pre-commit/action@v3.0.0 + + test: defaults: run: shell: bash @@ -18,6 +31,12 @@ jobs: fail-fast: false matrix: os: + - macos-latest - ubuntu-latest + - windows-latest steps: - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + - run: go install golang.org/x/lint/golint@latest + - run: golint -set_exit_status ./... + - run: go test ./... diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cce1fcc..9741210 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,23 +10,19 @@ permissions: jobs: main: + defaults: + run: + shell: bash + permissions: + contents: read runs-on: ubuntu-latest + strategy: + fail-fast: false steps: - - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + - uses: goreleaser/goreleaser-action@v4 with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.21" - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v4 - with: - # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser version: latest args: release --clean diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 508c172..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: test - -on: - pull_request: - branches: - - main - workflow_dispatch: - -jobs: - main: - defaults: - run: - shell: bash - permissions: - contents: read - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: "1.21" - - run: go test ./... diff --git a/README.md b/README.md index b86fd5b..cbba268 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,92 @@ -[![Build Status](https://travis-ci.org/gellel/slice.svg?branch=master)](https://travis-ci.org/gellel/slice) -[![Apache V2 License](https://img.shields.io/badge/license-Apache%20V2-blue.svg)](https://github.com/gellel/slice/blob/master/LICENSE) - # Slice -Package slice is a package of slice interfaces to handle common list-like operations on a collection of Go interfaces. Slice takes care of the allocation and deallocation of pointers and provides common list-like operations on the reference without the concern for handling the referencing and dereferencing of the pointer. +The Slice package is a versatile Go library designed to simplify common list-like operations on collections of Go interfaces. It abstracts away the complexities of memory allocation and deallocation of pointers while providing a rich set of list operations. Whether you're dealing with a homogeneous or heterogeneous collection, Slice has you covered. + +Key Features: -Slice contains a common slice type (exported as `slice.Slice`) that provides methods to perform traversal and mutation operations for a collection of Go interfaces. The `slice.Slice` struct can be wrapped in a generic Go struct to handle the allocation and retrieval of specific types. This has been done for all (as of writing this README) Go data types. +* Common List Operations: Slice provides a comprehensive set of list operations like appending, deleting, concatenating, mapping, reversing, and more, all seamlessly integrated into a simple API. +* Dynamic Memory Management: Forget about manual memory management; Slice takes care of allocating and deallocating memory as needed, making your code cleaner and safer. +* Type-Agnostic: Slice works effortlessly with a mix of data types, making it a valuable tool for dealing with collections of heterogeneous data. +* Generic Go Struct Wrapping: You can easily wrap the slice.Slice type in your custom Go struct to handle type-specific operations, allowing for robust, type-safe code. +* Intuitive Constructor Functions: Each Slice interface comes with a dedicated constructor function for creating slices conveniently. +* No Underlying Slice Exposure: To prevent mixing incompatible data types, Slice interfaces do not expose the underlying slice.Slice. While recommended for custom implementations, it's not mandatory. -Package slice comes with all Go primitive types as interfaces out of the box. Each interface is indicated by the _er_ suffix. +# Usage: -Each slice interface comes with a unique constructor function that takes zero to n arguments of the corresponding slice interface type. +## Installation +Add slice as a dependency to your Go project using the following command: -The slice interfaces do not expose the underlying `slice.Slice` to prevent a mixed collection. It is recommended to adopt this pattern when creating a custom implementation, but not required. +```sh +go get -u github.com/lindsaygelle/slice +``` -The package is built around the Go documentation pattern. Please consider using `godoc` when using this package. If you are using Go 1.12 or earlier, `godoc` should be included. All Go 1.13 users will need to grab this package using the `go get` flow. +## Docker +You can utilize slice within a Docker container with the provided Dockerfile. Here's how to build and run the container: -## Installing +Building the Docker container. +```sh +docker build . -t slice +``` -Use `go get` to retrieve the SDK to add it to your `GOPATH` workspace, or project's Go module dependencies. +Developing and running Go from within the Docker container. +```sh +docker run -it --rm --name slice slice +``` -```go get github.com/gellel/slice``` +## Docker-compose +A [`docker-compose.yml`](./docker-compose.yml) file has also been added for convenience. -To update the SDK use `go get -u` to retrieve the latest version of the SDK. +# Usage +To get started with the slice package, follow these steps: -```go get -u github.com/gellel/slice``` +Install the slice package using the go get command: -## Dependencies +```sh +go get github.com/lindsaygelle/slice +``` -The SDK includes a vendor folder containing the runtime dependencies of the SDK. The metadata of the SDK's dependencies can be found in the Go module file go.mod. +Import the package in your Go code: -## Go Modules +```Go +import "github.com/lindsaygelle/slice" +``` -If you are using Go modules, your go get will default to the latest tagged release version of the SDK. To get a specific release version of the SDK use `@` in your `go get` command. +Create Slice interfaces for the specific data types you want to work with. Use the provided constructor functions to initialize them. -```go get github.com/gelle/slice@``` +```Go +// Example for string slice +s := slice.NewStringer("apple", "banana", "cherry") +``` -To get the latest SDK repository change use @latest. +Use the methods provided by the Slice interface to perform various list-like operations. Here are some common operations: -## License +```Go +// Append elements to the slice +s.Append("date", "fig") + +// Check if an index is within bounds +inBounds := s.Bounds(2) + +// Pop the last element from the slice +poppedElement := s.Pop() +``` + +You can sort the slice and iterate over its elements easily: + +```Go +// Example for sorting and iteration +sortedSlice := s.Sort() +sortedSlice.Each(func(index int, value string) { + fmt.Println(index, value) +}) +``` + +That's it! You're ready to use the slice package to simplify your slice operations in Go. Explore the package documentation for a complete list of available methods and advanced usage patterns. -This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information. ## Snippets -Slice exports all primitive Go types as interfaces. +Each Slice interface is designed to handle a specific Go primitive type. You can easily create, manipulate, and check bounds on these slices. ```Go package main @@ -51,7 +94,7 @@ package main import ( "fmt" - "github.com/gellel/slice" + "github.com/lindsaygelle/slice" ) var ( @@ -91,7 +134,7 @@ A Slice interface implements all methods of slice.Slice. ```Go import ( - "github.com/gellel/slice" + "github.com/lindsaygelle/slice" ) func main() { @@ -115,7 +158,7 @@ This is the pattern implemented by this package and is used for the provided int package food import ( - "github.com/gellel/slice" + "github.com/lindsaygelle/slice" ) // Food is a struct that describes food. @@ -144,3 +187,9 @@ func (f *fooder) Prepend(food ...Food) Fooder { return f } ``` + +## Contributing +Contributions to Slice are welcome! If you have any ideas, bug reports, or enhancements, please submit them as GitHub issues or create a pull request with your changes. For major contributions, it is recommended to discuss your ideas first by creating an issue to ensure alignment with the project's goals and direction. Please see the [CONTRIBUTION](./CONTRIBUTING.md) file fore more details. + +## License +Slice is licensed under the MIT License. Feel free to use, modify, and distribute the code within this repository as per the terms of the license. Please see the [LICENSE](./LICENSE) file for more details.