dbrattli / Expression

Pragmatic functional programming for Python inspired by F#
https://expression.readthedocs.io
MIT License
424 stars 31 forks source link

Seq.map, TypeError: map() missing 1 required positional argument: 'mapper' #24

Closed imranypatel closed 3 years ago

imranypatel commented 3 years ago

Having some background in F# and just a beginner in Python, thought Expression lib worth exploring.

Using Ref https://cognitedata.github.io/Expression/expression/collections/seq.html and trying something as simple as:

    from expression.collections import Seq
    xs = Seq([1, 2, 3])
    ys = xs.pipe(
        Seq.map(lambda x: x + 1),
        Seq.filter(lambda x: x < 3)
    )

resulting in error:

  File "<ipython-input-54-c73530b41e79>", line 5, in <module>
      Seq.map(lambda x: x + 1),
  TypeError: map() missing 1 required positional argument: 'mapper'

Any help?

dbrattli commented 3 years ago

Thanks for reaching out. I'm fixing that example. It was written a long time ago when I wanted the code to look the same as F#. But now the code follows Python conventions. That means that all module names are lowercase. So a module Seq in F# becomes seq in Python. So the right way to do this now:

>>> from expression.collections import seq
>>> xs = seq.of_iterable([1, 2, 3])
>>> ys = xs.pipe(
    seq.map(lambda x: x + 1),
    seq.filter(lambda x: x < 3)
)

Also note that Expression also have a fluent syntax (similar to https://github.com/fsprojects/FSharp.Core.Fluent) which you can use (or combine with the example above)

>>> from expression.collections import Seq
>>> xs = Seq([1, 2, 3])
>>> ys = xs.map(lambda x: x + 1).filter(lambda x: x < 3)