lo
lo copied to clipboard
How to check if map key exists?
How to check if map key exists?
Is there something like: lo.KeyExixst()
it won't be more convenient than the built-in way I think;
_, haskey := mymap["baz"];
if haskey {
fmt.Println("has key baz")
}
It is not really more convenient in any way shape or form. Too much code for such a simple thing.
Actually was looking for something like?
lo.KeyExists(map, key)
Then you can use it in ternary like this:
result = lo.TernaryF(lo.KeyExists(map,key), doThis, doThat)
i expect this function too.
Added a pull request for this feature:
https://github.com/samber/lo/pull/366