Skip to content

Add ToStringMapStruct()#58

Open
albttx wants to merge 2 commits intospf13:masterfrom
albttx:HashSet
Open

Add ToStringMapStruct()#58
albttx wants to merge 2 commits intospf13:masterfrom
albttx:HashSet

Conversation

@albttx
Copy link
Copy Markdown

@albttx albttx commented Jan 11, 2018

Add the possibility to cast a slice into a hashset (map[string]struct{}).

The struct{} element worth 0 byte, and it's really useful for checking if a key is present. here an article about the empty struct.

This pull request is link with spf13/viper#437 to add this feature for parsing slice.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 11, 2018

CLA assistant check
All committers have signed the CLA.

Comment thread cast_test.go
expect map[string]struct{}
iserr bool
}{
{map[string]interface{}{"v1": true, "v2": false}, map[string]struct{}{"v1": struct{}{}, "v2": struct{}{}}, false},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that the casting that this library does implies some conversion, but how can both true and false be the same as struct{}{}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants