Module osbot_utils.fluent.Fluent_List

Expand source code
class Fluent_List(list):
    def __new__(cls, *args, **kwargs):
        return super().__new__(cls, args[0])

    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)

    def contains(self, item):
        return item in self

    def index(self, index):
        if index < self.size():
            return self[index]

    def first(self):
        if self.size() > 0:
            return self[0]

    def last(self):
        if self.size() > 0:
            return self[self.size() -1]

    def pop(self):
        """
        normal pop() function with the only variation being that empty lists will return None instead of raising an exception
        """
        if self.size() > 0:
            return super().pop()

    def push(self, value):
        self.append(value)
        return self

    def size(self):
        return len(self)

    def sorted(self):
        return sorted(self)

    def type(self):                         # todo: find a way to add this kind of methods to all Fluent Classes
        return type(self)


Fluent_List.sort = Fluent_List.sorted

Classes

class Fluent_List (*args, **kwargs)

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

Expand source code
class Fluent_List(list):
    def __new__(cls, *args, **kwargs):
        return super().__new__(cls, args[0])

    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)

    def contains(self, item):
        return item in self

    def index(self, index):
        if index < self.size():
            return self[index]

    def first(self):
        if self.size() > 0:
            return self[0]

    def last(self):
        if self.size() > 0:
            return self[self.size() -1]

    def pop(self):
        """
        normal pop() function with the only variation being that empty lists will return None instead of raising an exception
        """
        if self.size() > 0:
            return super().pop()

    def push(self, value):
        self.append(value)
        return self

    def size(self):
        return len(self)

    def sorted(self):
        return sorted(self)

    def type(self):                         # todo: find a way to add this kind of methods to all Fluent Classes
        return type(self)

Ancestors

  • builtins.list

Methods

def contains(self, item)
Expand source code
def contains(self, item):
    return item in self
def first(self)
Expand source code
def first(self):
    if self.size() > 0:
        return self[0]
def index(self, index)

Return first index of value.

Raises ValueError if the value is not present.

Expand source code
def index(self, index):
    if index < self.size():
        return self[index]
def last(self)
Expand source code
def last(self):
    if self.size() > 0:
        return self[self.size() -1]
def pop(self)

normal pop() function with the only variation being that empty lists will return None instead of raising an exception

Expand source code
def pop(self):
    """
    normal pop() function with the only variation being that empty lists will return None instead of raising an exception
    """
    if self.size() > 0:
        return super().pop()
def push(self, value)
Expand source code
def push(self, value):
    self.append(value)
    return self
def size(self)
Expand source code
def size(self):
    return len(self)
def sort(self)
Expand source code
def sorted(self):
    return sorted(self)
def sorted(self)
Expand source code
def sorted(self):
    return sorted(self)
def type(self)
Expand source code
def type(self):                         # todo: find a way to add this kind of methods to all Fluent Classes
    return type(self)