conv

package
v0.0.17-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package conv provides a simple way to convert between types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Conv

func Conv[T Numbers](def T, v any) T

Conv this can lose data i.e converting int32 to int8

func Deref

func Deref(v any) any

Deref returns the value of the pointer v if the pointer is nil then it returns untyped nil nil != (*int)(nil)

func NumberSlice

func NumberSlice[T, S Numbers](vs []S) []T

NumberSlice converts a slice of numbers (int8,int16, and so on ...)

func ToAnySlice

func ToAnySlice[T any](vs []T) []any

ToAnySlice converts a []T to []any, useful to pass params.

func ToNumberSlice

func ToNumberSlice[T Numbers](vs []any) []T

Convert []any to a typed T if an element has an invalid converstion a zero T will be used

func ToString

func ToString(v any) string

Types

type Numbers

type Numbers interface {
	constraints.Integer | constraints.Float
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL