cast

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package cast provides helpful functions for casting. It includes casting between different (castable)types for slice.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[R any, T any](from []T) ([]R, bool)

As creates new slice instance and casts from elements to result slice. It will return true when from slice is empty.

Example
package main

import (
	"fmt"

	"github.com/Prastiwar/Go-flow/reflection/cast"
)

func main() {
	arr := []interface{}{"1", "2", "3"}

	stringArr, ok := cast.As[string](arr)
	if !ok {
		panic("cannot cast between provided two types")
	}
	fmt.Println(stringArr)

}
Output:
[1 2 3]

Types

This section is empty.

Jump to

Keyboard shortcuts

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