GithubHelp home page GithubHelp logo

jarnsida / utils Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ghosind/utils

0.0 0.0 0.0 41 KB

Utilities for Golang

Home Page: https://pkg.go.dev/github.com/ghosind/utils

License: MIT License

Go 100.00%

utils's Introduction

Utilities for Golang

Test codecov Latest version License Badge Go Reference

A set of utilities functions for Golang.

PLEASE NOTE: This package is working with Go 1.18 and later versions.

Installation

You can install this package with go get command:

go get -u github.com/ghosind/utils

APIs

Conditional

  • Conditional[T any](cond bool, trueExpr, falseExpr T) T

    An alternative of ternary operator, same of cond ? trueExpr : falseExpr.

  • ConditionalExpr[T any](cond bool, trueExpr, falseExpr func() T) T

    An alternative to the conditional (ternary) operator (?:), it'll run expression by the conditional result.

  • Max[T constraints.Ordered](a, b T) T

    Gets the maximum value of two values.

  • Min[T constraints.Ordered](a, b T) T

    Gets the minimum value of two values.

Type

  • IsSameType(v1, v2 any) bool

    Compares two values' type.

  • IsSameRawType(v1, v2 any) bool

    Compares two values' type without pointer.

  • TypeOf(v any) string

    Gets the type of the value represented in string.

  • RawTypeOf(v any) string

    Gets the type string name without pointer.

  • GetElem(o any) any

    Gets element without pointer.

Pointer and Value

  • Pointer[T any](v T) *T

    Gets the pointer of a value.

  • func Value[T any](v *T) T

    Gets the value of a pointer, or the zero value of the type if the pointer is nil.

  • ValueWithDefault[T any](v *T, defaultValue T) T

    Gets the value of a pointer, or the default value if the pointer is nil.

  • PointerSlice[T any](v []T) *[]T

    Converts a slice to a pointer slice.

  • ValueSlice[T any](v *[]T) []T

    Converts a pointer slice to a slice.

  • PointerMap[K comparable, V any](v map[K]V) map[K]*V

    Converts a map to a pointer map.

  • ValueMap[K comparable, V any](v map[K]*V) map[K]V

    Converts a pointer map to a map.

License

Distributed under the MIT License. See LICENSE file for more information.

utils's People

Contributors

ghosind avatar mend-bolt-for-github[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.