Transforming parameters
We can declare any number of transformations that are to be applied to a parameter's specified value.
For example:
class Book(Configurable):
number_of_words_in_title = String('title').transform(str.split, len)
using_a_lambda_function_instead = String('title').transform(lambda x: len(x.split()))
book = Book(ConfigFactory.from_dict({'title': 'This is the title'}))
book.number_of_words_in_title # 4
book.using_a_lambda_function_instead # 4
Multiple transformations can be specified as arguments to transform
and will be applied in order (receiving the output of the previous transformation as an input, starting with the specified value).
Syntactic sugar for declaring transformations is available:
class Book(Configurable):
number_of_words_in_title = String('title') >> (str.split, len)
number_of_words_in_title = String('title') >> str.split >> len
Edited by Dominik Vilsmeier