@@ -291,6 +291,43 @@ func (m *Map) FirstLevelOf() map[string]*Map {
291
291
return newMap
292
292
}
293
293
294
+ // FirstLevelKeys returns the keys in the first level of the hierarchy
295
+ // of the current Map. For example the following Map:
296
+ //
297
+ // properties.Map{
298
+ // "uno.name": "Arduino/Genuino Uno",
299
+ // "uno.upload.tool": "avrdude",
300
+ // "uno.upload.protocol": "arduino",
301
+ // "uno.upload.maximum_size": "32256",
302
+ // "diecimila.name": "Arduino Duemilanove or Diecimila",
303
+ // "diecimila.upload.tool": "avrdude",
304
+ // "diecimila.upload.protocol": "arduino",
305
+ // "diecimila.bootloader.tool": "avrdude",
306
+ // "diecimila.bootloader.low_fuses": "0xFF",
307
+ // }
308
+ //
309
+ // will produce the following result:
310
+ //
311
+ // []string{
312
+ // "uno",
313
+ // "diecimila",
314
+ // }
315
+ //
316
+ // the order of the original map is preserved
317
+ func (m * Map ) FirstLevelKeys () []string {
318
+ res := []string {}
319
+ taken := map [string ]bool {}
320
+ for _ , k := range m .o {
321
+ first := strings .SplitN (k , "." , 2 )[0 ]
322
+ if taken [first ] {
323
+ continue
324
+ }
325
+ taken [first ] = true
326
+ res = append (res , first )
327
+ }
328
+ return res
329
+ }
330
+
294
331
// SubTree extracts a sub Map from an existing map using the first level
295
332
// of the keys hierarchy as selector.
296
333
// For example the following Map:
0 commit comments