Any object obj that supports obj(**member_dict) argument expansion as well as tuple and list can be used as the containing data structure. For tuple and list the member names are dropped but the order in which they were declared is maintained.
Transformations
Transformations can be applied to Groups in a similar way that they are applied to parameters (see Transformations). For example:
Sections
Groups can be assigned to separate sections similar to Class Sections but with the difference that the specified section won't be used to modify the members' names but instead to concatenate section and name when loading the parameter. For example:
Adding members
Parameters can be add to an existing group in the following ways:
Extending groups
Existing groups can be extended by others in the following way:
When extending a group it retains its original name / section and modifies the names of the other group's parameters by prepending the other group's name / section to the other group's members. Let's have a closer look:
In order to load the the group we can provide the following HOCON file:
class Rectangle(Configurable):
area = Group(
Integer('width'), Integer('height'),
as_=tuple
) >> (lambda x: x[0]*x[1])
r = Rectangle(dict(width=2, height=3))
r.area # 6
from pyhocon import ConfigFactory
class Rectangle(Configurable):
# The `name` keyword argument is used to specify group sections.
dimensions = Group(Integer('width'), Integer('height'), name='square')
r = Rectangle(ConfigFactory.parse_string(
"""square {
width = 2
height = 3
}"""
))
# Section names are not prepended to parameter names.
r.dimensions # {'width': 2, 'height': 3}
group = Group(Integer('i'))
group += Integer('j')
group.add(Integer('k'))