lo icon indicating copy to clipboard operation
lo copied to clipboard

How to check if map key exists?

Open lesichkovm opened this issue 2 years ago • 4 comments

How to check if map key exists?

Is there something like: lo.KeyExixst()

lesichkovm avatar Jun 08 '23 21:06 lesichkovm

it won't be more convenient than the built-in way I think;

_, haskey := mymap["baz"];
if haskey {
   fmt.Println("has key baz")
}

RaddadZ avatar Jun 13 '23 13:06 RaddadZ

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)

lesichkovm avatar Jun 15 '23 12:06 lesichkovm

i expect this function too.

trsteel avatar Jun 20 '23 12:06 trsteel

Added a pull request for this feature:

https://github.com/samber/lo/pull/366

lesichkovm avatar Jul 11 '23 05:07 lesichkovm