How to use the pfun.monoid.append function in pfun

To help you get started, we’ve selected a few pfun 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 suned / pfun / tests / test_monoid.py View on Github external
def test_none(n1, n2):
    assert empty(n1) is None
    assert append(n1, None) is None
    assert append(None, n1) is None
    assert append(n1, n2) is None
    assert append(n2, n1) is None
github suned / pfun / tests / test_monoid.py View on Github external
def test_int(i1, i2):
    assert empty(i1) == 0
    assert append(0, i1) == i1
    assert append(i1, 0) == i1
    assert append(i1, i2) == i1 + i2
    assert append(i2, i1) == i2 + i1
github suned / pfun / tests / test_monoid.py View on Github external
def test_int(i1, i2):
    assert empty(i1) == 0
    assert append(0, i1) == i1
    assert append(i1, 0) == i1
    assert append(i1, i2) == i1 + i2
    assert append(i2, i1) == i2 + i1
github suned / pfun / tests / test_monoid.py View on Github external
def test_list(l1, l2):
    assert empty(l1) == []
    assert append(l1, []) == l1
    assert append([], l1) == l1
    assert append(l1, l2) == l1 + l2
    assert append(l2, l1) == l2 + l1
github suned / pfun / tests / test_monoid.py View on Github external
def test_list(l1, l2):
    assert empty(l1) == []
    assert append(l1, []) == l1
    assert append([], l1) == l1
    assert append(l1, l2) == l1 + l2
    assert append(l2, l1) == l2 + l1
github suned / pfun / tests / test_monoid.py View on Github external
def test_str(s1, s2):
    assert empty(s1) == ''
    assert append(s1, '') == s1
    assert append('', s1) == s1
    assert append(s1, s2) == s1 + s2
    assert append(s2, s1) == s2 + s1
github suned / pfun / tests / test_monoid.py View on Github external
def test_int(i1, i2):
    assert empty(i1) == 0
    assert append(0, i1) == i1
    assert append(i1, 0) == i1
    assert append(i1, i2) == i1 + i2
    assert append(i2, i1) == i2 + i1
github suned / pfun / tests / test_monoid.py View on Github external
def test_tuple(t1, t2):
    assert empty(t1) == ()
    assert append(t1, ()) == t1
    assert append((), t1) == t1
    assert append(t1, t2) == t1 + t2
    assert append(t2, t1) == t2 + t1
github suned / pfun / pfun / writer.py View on Github external
to ``f``, and appending the monoid in this
                 instance with the result of ``f``
        """

        # this is kind of a hack:
        # I'm using ... as a special symbol that represents a monoid value
        # the type of which is yet to be determined.
        w = f(self.a)
        if w.m is ... and self.m is ...:
            m = ...
        elif w.m is ...:
            m = append(self.m, empty(self.m))  # type: ignore
        elif self.m is ...:
            m = append(empty(w.m), w.m)  # type: ignore
        else:
            m = append(self.m, w.m)  # type: ignore
        return Writer(w.a, m)  # type: ignore
github suned / pfun / pfun / writer.py View on Github external
:param f: Function to pass the value to
        :return: :class:`Writer` with result of
                 passing the value in this :class:`Writer`
                 to ``f``, and appending the monoid in this
                 instance with the result of ``f``
        """

        # this is kind of a hack:
        # I'm using ... as a special symbol that represents a monoid value
        # the type of which is yet to be determined.
        w = f(self.a)
        if w.m is ... and self.m is ...:
            m = ...
        elif w.m is ...:
            m = append(self.m, empty(self.m))  # type: ignore
        elif self.m is ...:
            m = append(empty(w.m), w.m)  # type: ignore
        else:
            m = append(self.m, w.m)  # type: ignore
        return Writer(w.a, m)  # type: ignore