Skip to content

1、是否可以模拟支持 tagged union type?2、API 命名不合理 #1

@hzqd

Description

@hzqd

如下代码:

enum Option<T> {
    Some(T) | None
}

如果用这个库,目前似乎是写不出来的。

import "github.com/lvyahui8/goenum"
type Option struct {
	goenum.Enum
}
var (
	Some = goenum.NewEnum[Option]("Some", 0) // 能否让这里的 0 作为可以携带的任意(any)值?
	None = goenum.NewEnum[Option]("None")
)
func() {
    some := *goenum.Value[Option]("Some")
    fmt.Println(some) // output: 0
    goenum.Set[Option]("Some", "a")
    foo := *goenum.Value[Option]("Some")
    fmt.Println(foo)  // output: a
}

另外目前的 ValueOfValueOfIgnoreCaseValues返回的是枚举变体enum variant所以名称应更改为VariantOfVariantOfIgnoreCaseVariants
Value  tagged union type 指的是 Variant 所携带的值

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions