Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f1d03b
commit 7ee1a90
Showing
3 changed files
with
23 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
class curry: | ||
def __init__(self, fun, *args, **kwargs): | ||
self.fun = fun | ||
""" | ||
Coding concepts. | ||
""" | ||
|
||
|
||
# pylint: disable=R0903 | ||
class Curry(object): | ||
""" Supports curry algorithm. | ||
defer calling a function with a specific set of parameters. | ||
""" | ||
|
||
def __init__(self, func, *args, **kwargs): | ||
""" Store arguments and function for later. """ | ||
self.func = func | ||
self.pending = args[:] | ||
self.kwargs = kwargs.copy() | ||
|
||
def __call__(self, *args, **kwargs): | ||
""" Call's the self.func with arguments now. """ | ||
|
||
if kwargs and self.kwargs: | ||
kw = self.kwargs.copy() | ||
kw.update(kwargs) | ||
kwarg = self.kwargs.copy() | ||
kwarg.update(kwargs) | ||
else: | ||
kw = kwargs or self.kwargs | ||
kwarg = kwargs or self.kwargs | ||
|
||
return self.fun(*(self.pending + args), **kw) | ||
return self.func(*(self.pending + args), **kwarg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters