After years of ruby and javascript I’ve started doing some work with python recently after joining the team at Agero. One of the first things I noticed was that a lot of folks in the python world pass around a lot of named arguments as a convention. My first example of this is the boto3 library used to interact with AWS in python (for proof, click here)
In an effort to reduce some of this parameter passing folks might be tempted to make their own class that reduces the number of parameters one needs to pass around. I offer a simpler functional solution taken from some patterns I’ve seen used in the functional javascript community.
Enter partial function application with a builder pattern. The following code highlights how one might create reusable functions without creating a domain specific class hierarchy.
Take the boto3 library. More specifically, take the scan function for a dyanmodb table. The following is an example of how one could use this concept to produce a convenient way to iterate through all items in a dynamo collection.
Now that we have these two simple base classes we can iterate through a collection of dynamodb objects using the following code.
Hopefully you found this code example useful. If you have any questions please leave a comment and I’ll try to help with an answer.