I believed you made thing overly complicated. You only have one hash table, and try to remove the entries that has remove_ of it. Not sure why you need to use reduce and map. You can use `each` to go through first key of the hash table, then use filter to filter out unwanted keys like,
# this class is use to setup owner and group class reduce_test { $hash = { attribute1 => 1, attribute2 => 2, attribute3 => 3, remove1 => 4, remove2 => 5, attribute4 => 6, attribute5 => 7, } notice("hash table => ${hash}") $h = $hash.filter | $items | { $items[0] !~ /^remove/ } notice("hash table after filtering out 'remove*' key = ${h}") } For the each part, I will left for you to figure out. -CK On Wed, Jun 5, 2019 at 8:09 AM Albert Shih <albert.s...@obspm.fr> wrote: > Hi > > > I try to write a code to delete some key inside a hash. So I got this > > > $_dataset = reduce($dataset.map |$key, $value| { {$key => > delete($value,['remove_key1','remove_key2','remove_key3'])} }) | $result, > $value | { deep_merge($result, $value)} > > so if > > $dataset = { > name1 => { > attr1 => > attr2 => > remove_key1 => > remove_key2 => > remove_key3 => > attr3 => > } > } > > it will end up > > $_dataset = { > name1 => { > attr1 => > attr2 => > attr3 => > } > } > > So it's working. > > But why this *not* working ? > > class ( > Optional[Hash] $remove_key = ['remove_key1','remove_key2','remove_key3'], > ) > { > > $_dataset = reduce($dataset.map |$key, $value| { {$key => > delete($value,$remove_key)} }) | $result, $value | { deep_merge($result, > $value)} > > } > > The problem are some key will be remove, some other not. I'm unable to > understand the difference or find out why it delete some key (event not in > the remove_key array), and keep some other. > > Regards. > > > > > > > -- > Albert SHIH > DIO bātiment 15 > Observatoire de Paris > xmpp: j...@obspm.fr > Heure local/Local time: > Wed 05 Jun 2019 04:57:36 PM CEST > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to puppet-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/20190605150914.GA7441%40io.chezmoi.fr > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAC9thQUEjMhAwbJrjH%2BQRNPerTnjsNqCbJQRD8P6uFuEuRfVBw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.