Skip to content

Unexpected behavior of _ shortcut on __call__ execution #30

Description

@mikebohdan

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]: ','

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions