Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior of _ shortcut on __call__ execution #30

Open
mikebohdan opened this issue Sep 1, 2017 · 1 comment
Open

Unexpected behavior of _ shortcut on __call__ execution #30

mikebohdan opened this issue Sep 1, 2017 · 1 comment

Comments

@mikebohdan
Copy link

When I try to execute following code it throwing an error:

In [49]: from fn import _

In [50]: from fn import F

In [51]: f = F()

In [52]: a = f >> _.split >> _(',')

In [53]: a('1,2,3')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-53-3db68dd60b11> in <module>()
----> 1 a('1,2,3')

/path/to/package/fn/func.pyc in __call__(self, *args, **kwargs)
     53     def __call__(self, *args, **kwargs):
     54         """Overload apply operator"""
---> 55         return self.f(*args, **kwargs)
     56 
     57 

/path/to/package/fn/func.pyc in <lambda>(*args, **kwargs)
     34         in other methods.
     35         """
---> 36         return cls(lambda *args, **kwargs: f(g(*args, **kwargs)))
     37 
     38     def __ensure_callable(self, f):

TypeError: 'str' object is not callable

I expect that previous code should works like this:

a = lambda x: x.split(',')

Actually it works if we rewrite it a little bit:

In [61]: from fn import _

In [62]: from fn import F

In [63]: f = F()

In [64]: a = f >> _.split >> (lambda x: x(','))

In [65]: a('1,2,3')
Out[65]: ['1', '2', '3']

So, the problem in the method _Callable.__call__.
By default _calback=identity and we have following:

In [6]: from fn import _

In [7]: _(',')
Out[7]: ','
@Digenis
Copy link
Member

Digenis commented Sep 27, 2017

See kachayev#79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants