Expression icon indicating copy to clipboard operation
Expression copied to clipboard

Difference to dry-python/returns

Open jim108dev opened this issue 4 years ago • 7 comments
trafficstars

Hi! Thank you for creating this repo. I was wondering what exactly are the pros and cons opposite to https://github.com/dry-python/returns. Maybe someone could make this more clear in the Readme.

Thank you!

jim108dev avatar Nov 04 '21 08:11 jim108dev

Thanks for the input. Returns looks like a great and well made library for Python. This library (Expression) tries to stay close to F# abstractions and naming, i.e by using Expression you will learn some F# as well. But I don't think we should try to compare ourselves with others. I really don't know Returns and have never used it myself.

dbrattli avatar Nov 10 '21 07:11 dbrattli

Hi @dbrattli, thanks for the reply. What I really do a lot lately is piping with pandas and it is not type safe with pylance.,e. g.

df_train_features = (df_train_source.pipe(filter_value, "Month", 9)
   .pipe(filter_columns, FEATURES)
   .pipe(dropna)
)

Does Expression offer a solution for that?

jim108dev avatar Nov 11 '21 05:11 jim108dev

Yes, I think so. But you would need to craft your handlers so that you can partially apply them (when they need multiple arguments) e.g:

Screenshot 2021-11-11 at 07 28 48

dbrattli avatar Nov 11 '21 06:11 dbrattli

I see. On the readme it says: "Avoid currying, not supported in Python by default and not a well known concept by Python programmers." Does this mean I have to write inner functions for most of my functions now?

jim108dev avatar Nov 11 '21 09:11 jim108dev

Maybe. The problem with currying is that the function also looses it's type. But there's perhaps another solution. Let me check ...

dbrattli avatar Nov 11 '21 12:11 dbrattli

Well, piping only works with functions taking a single argument, so we need to turn the handlers into single argument functions. Currying or applying a function partially is not really the normal way of programming in Python, but e.g. decorations are commonly used (returning inner functions). So a few non-magic decorators could do the trick. I'm considering adding these decorators #49 that should hopefully do the trick.

dbrattli avatar Nov 11 '21 18:11 dbrattli

The biggest difference I think is that expression supports pylance, but returns only supports mypy.

phi-friday avatar Feb 03 '23 17:02 phi-friday