Skip to main content

Custom operators for python

Project description

COPERATOR Usage

factory_operator usage

from coperator.myoperator import factory_operator


class Example:
    """Example."""

    def __init__(self, x: int) -> None:
        """__init__.

        :param x:
        :type x: int
        :rtype: None
        """
        self._x: int = self.set_x(x)

    def set_x(self, x: int) -> int:
        """set_x.

        :param x:
        :type x: int
        :rtype: int
        """
        return x

    def get_x(self) -> int:
        """get_x.

        :rtype: int
        """
        return self._x

    def __str__(self) -> str:
        """__str__.

        :rtype: str
        """
        return str(self.get_x())


@factory_operator(Example, Example, Example)
def op(A: Example, B: Example) -> Example:
    """op.

    :param A:
    :type A: Example
    :param B:
    :type B: Example
    :rtype: Example
    """
    return Example(A.get_x() + B.get_x())


E1: Example = Example(1)
E2: Example = Example(2)
E3: Example = Example(3)

print(E1 * op * E2 * op * E3)
6

monad usage

from coperator.monad import monad

 def neg(i):
     return -i

 print(monad("1")(int)(neg)(str)(None))
 print(monad("x")(int)(neg)(str)(None))

 def func1(i):
     return monad(i)(int)(neg)(str)(None)

 print(list(map(func1,["1",2,"z"])))
'-1'
None
['-1','-2',None]

LICENSE

MIT License

Copyright (c) 2020 Jean Carlo Jimenez Giraldo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coperator-1.1.12.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file coperator-1.1.12.tar.gz.

File metadata

  • Download URL: coperator-1.1.12.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

File hashes

Hashes for coperator-1.1.12.tar.gz
Algorithm Hash digest
SHA256 596ff0c39515d81a218e384cbe1688d4e9b26cd1582fb48e454126c52f34ee75
MD5 65827dcac86168d91517537f0a4566c7
BLAKE2b-256 ac085ba36c1236fa5c56754d17594610593ac86373f490d477cecb96e75483cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page