Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg BackgroundAt the moment it is difficult to flatten out a complex structure. There is a flatten in standard lib that creates a flat copy of a tree of {{Array}} objects, and it errors if given a Hash. If the restriction was lifted to also support Hash, Ruby flatten method flattens a hash by making an array of keys and values. That makes the result hard to use if it is a mix of arrays and hashes.It is very useful to be able to iterate over such a tree instead of creating a copy, and it is of value to iterate over it in different ways. This is what the flat_each does.To describe what is wanted; imagine the two functions {{each_element}}, and {{each_container}} (these are not the functions we want at the end; they are too special, but they serve as illustration).{{each_element(Iterable $x)}}This function visits each container and leaf in the tree $x and calls a given block with 1.3 parameters. The block gets container, index, and value if defining three parameters, if using 2 arguments the container and index is delivered as a tuple, and if using 1 arg the three args are delivered as a Triple. The first yielded value is the given argument value. Each element in the tree is yielded with parent before children, depth first.When not given a block, each_element produces an Iterator that yields a triplet.{{each_container(Iterable $x)}}This function is he same as to each_element but skips children that are not containers. This enables doing inner loops conditionally.What we should do instead is to first implement {{next()}} since that makes it possible to do general skipping and pruning; {{next(true)}} means skip this element and its children and {{next()}}, or {{next(false)}} to mean "do not prune", take next element I am done with the one you just gave me.ProposalImplement flat_each such that:* It accepts an Iterable and a required block* It produces an Iterator if not given a block* When given a block, it produces the given first argument* It yields 1-3 arguments as described for each_element* The value produced by the block is ignored (as for a regular each)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.Implement flat_reduce such that:* It accepts an Any and a required block* if value is not Iterable, the given value is yielded and nothing more, else every value in the iterable is yielded to the block* It produces an Iterator if not given a block* When given a block, it produces a result that is determined by the block** For each given container* It yields up to 6 arguments, exact rules t.b.d (see below)* The value produced by the block represents the next state (see below)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.* In contrast to the existing {{reduce}} the {{flat_reduce}} does not take an optional starting value, as that is controlled via the $direction.Example:{code:puppet}$a_tree.flat_reduce |$tree, $level, $direction, $container, $key, $val | { ... }$tree is
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg BackgroundAt the moment it is difficult to flatten out a complex structure. There is a flatten in standard lib that creates a flat copy of a tree of {{Array}} objects, and it errors if given a Hash. If the restriction was lifted to also support Hash, Ruby flatten method flattens a hash by making an array of keys and values. That makes the result hard to use if it is a mix of arrays and hashes.It is very useful to be able to iterate over such a tree instead of creating a copy, and it is of value to iterate over it in different ways. This is what the flat_each does.To describe what is wanted; imagine the two functions {{each_element}}, and {{each_container}} (these are not the functions we want at the end; they are too special, but they serve as illustration).{{each_element(Iterable $x)}}This function visits each container and leaf in the tree $x and calls a given block with 1.3 parameters. The block gets container, index, and value if defining three parameters, if using 2 arguments the container and index is delivered as a tuple, and if using 1 arg the three args are delivered as a Triple. The first yielded value is the given argument value. Each element in the tree is yielded with parent before children, depth first.When not given a block, each_element produces an Iterator that yields a triplet.{{each_container(Iterable $x)}}This function is he same as to each_element but skips children that are not containers. This enables doing inner loops conditionally.What we should do instead is to first implement {{next()}} since that makes it possible to do general skipping and pruning; {{next(true)}} means skip this element and its children and {{next()}}, or {{next(false)}} to mean "do not prune", take next element I am done with the one you just gave me.ProposalImplement flat_each such that:* It accepts an Iterable and a required block* It produces an Iterator if not given a block* When given a block, it produces the given first argument* It yields 1-3 arguments as described for each_element* The value produced by the block is ignored (as for a regular each)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.Implement flat_reduce such that:* It accepts an Any and a required block* if value is not Iterable, the given value is yielded and nothing more, else every value in the iterable is yielded to the block* It produces an Iterator if not given a block* When given a block, it produces a result that is determined by the block** For each given container* It yields up to 6 arguments, exact rules t.b.d (see below)* The value produced by the block represents the next state (see below)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.* In contrast to the existing {{reduce}} the {{flat_reduce}} does not take an optional starting value, as that is controlled via the $direction.Example:{code:puppet}$a_tree.flat_reduce |$tree, $level, $direction, $container, $key, $val | { ... }$tree is
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg BackgroundAt the moment it is difficult to flatten out a complex structure. There is a flatten in standard lib that creates a flat copy of a tree of {{Array}} objects, and it errors if given a Hash. If the restriction was lifted to also support Hash, Ruby flatten method flattens a hash by making an array of keys and values. That makes the result hard to use if it is a mix of arrays and hashes.It is very useful to be able to iterate over such a tree instead of creating a copy, and it is of value to iterate over it in different ways. This is what the flat_each does.To describe what is wanted; imagine he the two functions {{ each_element }} , and {{ each_container }} (these are not the functions we want at the end; they are too special, but they serve as illustration). {{ each_element(Iterable $x) }} This function visits each container and leaf in the tree $x and calls a given block with 1.3 parameters. The block gets container, index, and value if defining three parameters, if using 2 arguments the container and index is delivered as a tuple, and if using 1 arg the three args are delivered as a Triple. The first yielded value is the given argument value. Each element in the tree is yielded with parent before children, depth first.When not given a block, each_element produces an Iterator that yields a triplet. {{ each_container(Iterable $x) }} This function is he same as to each_element but skips children that are not containers. This enables doing inner loops conditionally.What we should do instead is to first implement {{next()}} since that makes it possible to do general skipping and pruning; {{next(true)}} means skip this element and its children and {{next()}}, or {{next(false)}} to mean "do not prune", take next element I am done with the one you just gave me.ProposalImplement flat_each such that:* It accepts an Iterable and a required block* It produces an Iterator if not given a block* When given a block, it produces the given first argument* It yields 1-3 arguments as described for each_element* The value produced by the block is ignored (as for a regular each)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.Implement flat_reduce such that:* It accepts an Any and a required block* if value is not Iterable, the given value is yielded and nothing more, else every value in the iterable is yielded to the block* It produces an Iterator if not given a block* When given a block, it produces a result that is determined by the block** For each given container* It yields up to 6 arguments, exact rules t.b.d (see below)* The value produced by the block represents the next state (see below)* If next is called, the value given to next determines if iteration continues with the next in order {{next(false)}}/{{next()}}, or if it prunes {{next(true)}}.* In contrast to the existing {{reduce}} the {{flat_reduce}} does not take an optional starting value, as that is controlled via the $direction.Example:{code:puppet}$a_tree.flat_reduce |$tree, $level, $direction, $container, $key,
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Sprint: Agent Language Triage Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Ethan Brown updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Ethan Brown Sprint: Agent Triage Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Ethan Brown updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Ethan Brown Team: Puppet Developer Experience Agent Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Fix Version/s: PUP 4.y Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Labels: triaged Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Component/s: Language Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Priority: Normal Minor Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Team: Puppet Developer Support Add Comment This message was sent by Atlassian JIRA (v6.4.14#64029-sha1:ae256fe) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Sprint: Language Triage Add Comment This message was sent by Atlassian JIRA (v6.4.13#64028-sha1:b7939e9) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg updated an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Change By: Henrik Lindberg Fix Version/s: PUP 4.x Add Comment This message was sent by Atlassian JIRA (v6.4.12#64027-sha1:e3691cc) -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at https://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/d/optout.
Jira (PUP-5893) Add tree iterative functions - tree_each, and tree_reduce
Title: Message Title Henrik Lindberg created an issue Puppet / PUP-5893 Add tree iterative functions - tree_each, and tree_reduce Issue Type: New Feature Assignee: Unassigned Created: 2016/02/12 10:11 AM Priority: Normal Reporter: Henrik Lindberg Background At the moment it is difficult to flatten out a complex structure. There is a flatten in standard lib that creates a flat copy of a tree of Array objects, and it errors if given a Hash. If the restriction was lifted to also support Hash, Ruby flatten method flattens a hash by making an array of keys and values. That makes the result hard to use if it is a mix of arrays and hashes. It is very useful to be able to iterate over such a tree instead of creating a copy, and it is of value to iterate over it in different ways. This is what the flat_each does. To describe what is wanted; imagine he two functions each_element, and each_container (these are not the functions we want at the end; they are too special, but they serve as illustration). each_element(Iterable $x) This function visits each container and leaf in the tree $x and calls a given block with 1.3 parameters. The block gets container, index, and value if defining three parameters, if using 2 arguments the container and index is delivered as a tuple, and if using 1 arg the three args are delivered as a Triple. The first yielded value is the given argument value. Each element in the tree is yielded with parent before children, depth first. When not given a block, each_element produces an Iterator that yields a triplet. each_container(Iterable $x) This function is he same as to each_element but skips children that are not containers. This enables doing inner loops