Hacker News new | past | comments | ask | show | jobs | submit login

Just came back to python after several years in javascript. I've found that the functions you need are often already provided in the standard library (for example the `operator` module[1]).

So where in javascript you would write:

    const double = x => x * 2
In python you can simply write:

    from operator import mul
    double = mul(2)
[1]: https://docs.python.org/2/library/operator.html



The Python equivalent of your JavaScript example is simply:

    def double(x): return x * 2
Python's `lambda` construct creates anonymous functions - its limitations mean it should only be used when anonymity is required. If a function is to be given a name, there is no reason to use a lambda over standard function syntax.


That won't work, you have to use something like partial instead if you want to use the operator module:

    from functools import partial
    import operator
    double = partial(operator.mul, 2)
And at that point I think it would way simpler to just define a normal function.


That don't work since you need to use `partial` on `mul`.

I'm a big fan of the way Haskell manages operators and partial application.

    double :: Num a => a -> a
    double = (2 *)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: