#!/usr/bin/env python
##############################################################################
#
# diffpy.srfit Complex Modeling Initiative
# (c) 2014 Brookhaven Science Associates,
# Brookhaven National Laboratory.
# All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################
"""Functions for binding arguments of callable objects."""
# FIXME: remove this line when black and docformatter agree.
[docs]
class bind2nd(object):
"""Freeze the second argument of a callable to a constant.
Calling the instance as ``bound(a, *args, **kwargs)`` calls
``func(a, arg1, *args, **kwargs)``.
Parameters
----------
func : callable
The callable whose second argument is frozen.
arg1
The value passed as the second argument of ``func``.
"""
def __init__(self, func, arg1):
self.func = func
self.arg1 = arg1
return
def __call__(self, *args, **kwargs):
boundargs = (args[0], self.arg1) + args[1:]
return self.func(*boundargs, **kwargs)