kutil

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](v any) (T, bool)

As 尝试将任意类型 v 转换为 T 类型,内部基于 gconv 实现,支持: 1. 基本类型互转(如 string ↔ int、bool ↔ float 等); 2. 复合类型转换(如 slice ↔ array、map ↔ struct 等,需符合 gconv 规则)。 返回转换后的值和是否成功(true 表示转换有效)。

func If

func If[T any](condition bool, trueVal any, falseVal ...any) T

If 实现两种功能: 1. 三元运算:当传入 trueVal 和 falseVal 时,返回对应值 2. 条件执行:当传入 f(或 f、g)时,执行对应函数 注:两种功能通过参数类型区分,互斥使用 注意:Go 语言中,函数参数会先求值再传递,因此如果传入的函数有副作用,需要注意顺序问题。

Types

This section is empty.

Jump to

Keyboard shortcuts

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