How to use the flupy.fluent.Empty function in flupy

To help you get started, we’ve selected a few flupy 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 olirice / flupy / flupy / fluent.py View on Github external
    def first(self, default=Empty()):
        """Return the first item of the iterable. Raise IndexError if empty or default if provided.

               >>> flu.first([0, 1, 2, 3])
               0
               >>> flu.first([], default='some_default')
               'some default'

        when *default* is not provided and the iterable is empty, raise IndexError
        """
        x = default
        for x in self:
            return x
        if isinstance(x, Empty):
            raise IndexError("Empty iterator")
        return default
github olirice / flupy / flupy / fluent.py View on Github external
    def last(self, default=Empty()):
        """Return the last item of the iterble. Raise IndexError if empty or default if provided.

               >>> flu.last([0, 1, 2, 3])
               3
               >>> flu.last([], default='some_default')
               'some default'
        """
        x = default
        for x in self:
            pass
        if isinstance(x, Empty):
            raise IndexError("Empty iterator")
        return x
github olirice / flupy / flupy / fluent.py View on Github external
def tail(self, n: int = 10, container_type: Type = list):
        """Return up to the last *n* elements from the iterable

               >>> flu.tail(range(20))
               [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

               >>> flu.tail(range(15), n=2)
               [18, 19]
        """
        for val in self.window(n, fill_value=Empty()):
            pass
        return container_type([x for x in val if not isinstance(x, Empty)])
github olirice / flupy / flupy / fluent.py View on Github external
def first(self, default=Empty()):
        """Return the first item of the iterable. Raise IndexError if empty or default if provided.

               >>> flu.first([0, 1, 2, 3])
               0
               >>> flu.first([], default='some_default')
               'some default'

        when *default* is not provided and the iterable is empty, raise IndexError
        """
        x = default
        for x in self:
            return x
        if isinstance(x, Empty):
            raise IndexError("Empty iterator")
        return default

flupy

Method chaining built on generators

MIT
Latest version published 2 months ago

Package Health Score

76 / 100
Full package analysis