Source code for fictive.patterns.sequences

"""
Common patterns for working with :term:`sequence` objects

"""

import typing


[docs]def append_distinct(current: typing.Sequence, new: typing.Sequence): """ combine `current` and any values from `new` not already in `current` .. doctest:: >>> from fictive.patterns.sequences import append_distinct >>> current = (2, 4, 6, 8, 10) >>> new = [1, 2, 3, 4, 5] >>> append_distinct(current, new) (2, 4, 6, 8, 10, 1, 3, 5) :param current: the existing sequence :type current: `collections.abc.Sequence` :param new: the sequence of potential values to append :type new: `collections.abc.Sequence` :return: the new sequecne :rtype: the same type as `current` """ return current + type(current)(i for i in new if i not in current)