How to use the pypeline.core.arrows.arrow.Arrow function in Pypeline

To help you get started, we’ve selected a few Pypeline examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ianj-als / pypeline / src / pypeline / core / arrows / function_arrow.py View on Github external
# WATCH OUT FOR OPERATOR PRECEDENCE!!!
#
# ** is higher than >> is higher than &
#
#
# See:
#  Publications:
#    http://www.cse.chalmers.se/~rjmh/Papers/arrows.pdf
#    http://www.soi.city.ac.uk/~ross/papers/notation.pdf
#
#  Tutorials:
#    http://www.haskell.org/arrows/
#    http://www.haskell.org/haskellwiki/Arrow_tutorial
#    http://en.wikibooks.org/wiki/Haskell/Understanding_arrows
#
class FunctionArrow(Arrow):
    def __init__(self, func):
        if type(func) is not types.FunctionType and \
           type(func) is not types.MethodType:
            raise ValueError("Must be a function or method")

        Arrow.__init__(self)
        self._func = func

    #
    # (>>>) composition
    #
    #       +---------+           +---------+
    # b --->+--- f ---+--- c ---->+--- g ---+---> d
    #       +---------+           +---------+
    def __rshift__(self, other):
        if not isinstance(other, FunctionArrow):
github ianj-als / pypeline / src / pypeline / core / arrows / kleisli_arrow.py View on Github external
# You should have received a copy of the GNU Lesser General Public License
# along with Pypeline.  If not, see .
#
import types

from pypeline.core.arrows.arrow import Arrow


#
# Kleisli arrows of a monad
#
# See:
#  Publications:
#    http://www.cse.chalmers.se/~rjmh/Papers/arrows.pdf
#
class KleisliArrow(Arrow):
    #
    # patcher :: Monad m => a -> m a
    # function :: Monad m => a -> m b
    #
    def __init__(self, patcher, f):
        if not isinstance(patcher, types.FunctionType) and not isinstance(patcher, types.MethodType):
            raise ValueError("Patcher must be a function")
        if f and (not isinstance(f, types.FunctionType) and
                  not isinstance(f, types.MethodType)):
            raise ValueError("Function must be a function")

        Arrow.__init__(self)
        self._patcher = patcher
        self._func = f

    # arr f = K(\b -> return(f b))