<commit_before># -*- coding: utf-8 -*-

__author__ = '<NAME>'
__email__ = '<EMAIL>'
__version__ = '0.1.7'

from sys import getsizeof


class Maybe(object):
    pass


class Nothing(Maybe):
    def is_some(self):
        return False

    def is_none(self):
        return True

    def get(self):
        raise Exception('No such element')

    def or_else(self, els=None):
        if callable(els):
            return els()

        return els

    def __call__(self, *args, **kwargs):
        return Nothing()

    # region Comparison

    def __cmp__(self, other):
        if other.__class__ == Nothing:
            return 0

        return -1

    def __eq__(self, other):
        if other.__class__ == Nothing:
            return True

        if other is None:
            return True

        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def __lt__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return True

        return True if other else False

    def __gt__(self, other):
        return False

    def __le__(self, other):
        return True

    def __ge__(self, other):
        if other.__class__ == Nothing:
            return True

        if other is None:
            return True

        return False

    # endregion

    def __getattr__(self, name):
        return Nothing()

    # region Dict
    def __len__(self):
        return 0

    def __getitem__(self, key):
        return Nothing()

    def __setitem__(self, key, value):
        pass

    def __delitem__(self, key):
        pass

    # endregion

    # region Custom representation
    def __repr__(self):
        return 'Nothing'

    def __str__(self):
        return 'Nothing'

    def __unicode__(self):
        return unicode(None)

    def __nonzero__(self):
        return False

    # endregion


class Something(Maybe):
    def __init__(self, value):
        self.__value = value

    def __call__(self, *args, **kwargs):
        return maybe(self.__value(*args, **kwargs))

    # region Comparison
    def __cmp__(self, other):
        if other.__class__ == Nothing:
            return 1

        if other.__class__ == Something:
            return cmp(self.get(), other.get())
        else:
            return cmp(self.get(), other)

    def __eq__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() == other.get()

        return self.get() == other

    def __ne__(self, other):
        return not self.__eq__(other)

    def __lt__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() < other.get()

        return self.get() < other

    def __gt__(self, other):
        if other.__class__ == Nothing:
            return True

        if other.__class__ == Something:
            return self.get() > other.get()

        return self.get() > other

    def __le__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() <= other.get()

        return self.get() <= other

    def __ge__(self, other):
        if other.__class__ == Nothing:
            return True

        if other.__class__ == Something:
            return self.get() >= other.get()

        return self.get() >= other
    # endregion

    def is_some(self):
        return True

    def is_none(self):
        return False

    def get(self):
        return self.__value

    # pylint: disable=W0613
    def or_else(self, els=None):
        return self.__value

    def __getattr__(self, name):
        try:
            return maybe(getattr(self.__value, name))
        except Exception:
            return Nothing()
<commit_msg>Added or_none and or_empty_list helper methods<commit_after># -*- coding: utf-8 -*-

__author__ = '<NAME>'
__email__ = '<EMAIL>'
__version__ = '0.1.7'

from sys import getsizeof


class Maybe(object):
    pass


class Nothing(Maybe):
    def is_some(self):
        return False

    def is_none(self):
        return True

    def get(self):
        raise Exception('No such element')

    def or_else(self, els=None):
        if callable(els):
            return els()

        return els

    def or_none(self):
        return self.or_else()

    def or_empty_list(self):
        return self.or_else([])

    def __call__(self, *args, **kwargs):
        return Nothing()

    # region Comparison

    def __cmp__(self, other):
        if other.__class__ == Nothing:
            return 0

        return -1

    def __eq__(self, other):
        if other.__class__ == Nothing:
            return True

        if other is None:
            return True

        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def __lt__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return True

        return True if other else False

    def __gt__(self, other):
        return False

    def __le__(self, other):
        return True

    def __ge__(self, other):
        if other.__class__ == Nothing:
            return True

        if other is None:
            return True

        return False

    # endregion

    def __getattr__(self, name):
        return Nothing()

    # region Dict
    def __len__(self):
        return 0

    def __getitem__(self, key):
        return Nothing()

    def __setitem__(self, key, value):
        pass

    def __delitem__(self, key):
        pass

    # endregion

    # region Custom representation
    def __repr__(self):
        return 'Nothing'

    def __str__(self):
        return 'Nothing'

    def __unicode__(self):
        return unicode(None)

    def __nonzero__(self):
        return False

    # endregion


class Something(Maybe):
    def __init__(self, value):
        self.__value = value

    def __call__(self, *args, **kwargs):
        return maybe(self.__value(*args, **kwargs))

    # region Comparison
    def __cmp__(self, other):
        if other.__class__ == Nothing:
            return 1

        if other.__class__ == Something:
            return cmp(self.get(), other.get())
        else:
            return cmp(self.get(), other)

    def __eq__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() == other.get()

        return self.get() == other

    def __ne__(self, other):
        return not self.__eq__(other)

    def __lt__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() < other.get()

        return self.get() < other

    def __gt__(self, other):
        if other.__class__ == Nothing:
            return True

        if other.__class__ == Something:
            return self.get() > other.get()

        return self.get() > other

    def __le__(self, other):
        if other.__class__ == Nothing:
            return False

        if other.__class__ == Something:
            return self.get() <= other.get()

        return self.get() <= other

    def __ge__(self, other):
        if other.__class__ == Nothing:
            return True

        if other.__class__ == Something:
            return self.get() >= other.get()

        return self.get() >= other
    # endregion

    def is_some(self):
        return True

    def is_none(self):
        return False

    def get(self):
        return self.__value

    # pylint: disable=W0613
    def or_else(self, els=None):
        return self.__value

    def or_none(self):
        return self.or_else()

    def or_empty_list(self):
        return self.or_else([])

    def __getattr__(self, name):
        try:
            return maybe(getattr(self.__value, name))
        except Exception:
            return Nothing()

{'fraction_non_alphanumeric': 0.09860373161991845, 'fraction_numerical': 0.002965525763005066, 'mean_word_length': 1.834033613445378, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6395147', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2207, 'n_words': 679}