File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -343,7 +343,7 @@ Manipulates an iteratee (map, slice) and transforms it to to a flattened collect
343343 funk.Get
344344........
345345
346- Retrieves the value at path of struct(s).
346+ Retrieves the value at path of struct(s) or map(s) .
347347
348348.. code-block :: go
349349
@@ -381,6 +381,34 @@ Retrieves the value at path of struct(s).
381381 funk.Get(foo, "Bar.Bars.Bar.Name") // []string{"Level2-1", "Level2-2"}
382382 funk.Get(foo, "Bar.Name") // Test
383383
384+ ``funk.Get `` also support ``map `` values:
385+
386+ .. code-block :: go
387+
388+ bar := map[string]interface{}{
389+ "Name": "Test",
390+ }
391+
392+ foo1 := map[string]interface{}{
393+ "ID": 1,
394+ "FirstName": "Dark",
395+ "LastName": "Vador",
396+ "Age": 30,
397+ "Bar": bar,
398+ }
399+
400+ foo2 := &map[string]interface{}{
401+ "ID": 1,
402+ "FirstName": "Dark",
403+ "LastName": "Vador",
404+ "Age": 30,
405+ } // foo2.Bar is nil
406+
407+ funk.Get(bar, "Name") // "Test"
408+ funk.Get([]map[string]interface{}{foo1, foo2}, "Bar.Name") // []string{"Test"}
409+ funk.Get(foo2, "Bar.Name") // nil
410+
411+
384412 ``funk.Get `` also handles ``nil `` values:
385413
386414.. code-block :: go
You can’t perform that action at this time.
0 commit comments