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

Adds complex math expressions support #3

Merged
merged 9 commits into from
Jul 17, 2020

Conversation

thepabloaguilar
Copy link
Member

@thepabloaguilar thepabloaguilar commented Jul 11, 2020

I've implemented the _MathExpression callable class to work with complex math expressions.
It accumulate the operations when the instance is called all the operations are reduced to get the final result!

Example:

>>> from lambdas import _MathExpression
>>> complex_expression = (10 ** 2) / _MathExpression() * 10
>>> complex_expression(2)
500.0

I've modified _Callable class too, to use the _MathExpression in its math operation and now we can use it normally, no side effects:

>>> from lambdas import _
>>> complex_expression = (10 ** 2) / _ * 10
>>> complex_expression(2)
500.0

TODO:

  • Reach coverage 100% (in fact was 97% of all coverage, but 100% of my implementation)

closes #1

@thepabloaguilar
Copy link
Member Author

@sobolevn I'm not sure about typing, could you take a look please?

lambdas/__init__.py Outdated Show resolved Hide resolved
@thepabloaguilar thepabloaguilar changed the title [WIP] Adds complex math expressions support Adds complex math expressions support Jul 11, 2020
@thepabloaguilar thepabloaguilar requested a review from sobolevn July 11, 2020 19:00
@thepabloaguilar
Copy link
Member Author

@sobolevn I've reached 97% of test coverage, because _fmap is never called and we don't have any tests for and, or, etc.
I opened #4 to convert all functions:

# FROM
class _Callable(object):
    __and__: Callable[['_Callable', T1], Callable[[T1], T1]] = _fmap(operator.and_)

# TO
class _Callable(object):
    def __and__(self, other: Any) -> Callable[['_Callable', T1], Callable[[T1], T1]]:
        return _fmap(operator.and_)

After the conversion we will have to write all the tests, I can write them after this PR!

@thepabloaguilar
Copy link
Member Author

@sobolevn is something else needed?

@sobolevn sobolevn merged commit 61582df into dry-python:master Jul 17, 2020
@sobolevn
Copy link
Member

Thanks a lot!

@thepabloaguilar thepabloaguilar deleted the feature/issue-1 branch July 17, 2020 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Math operations
2 participants