# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/01_CondenseEditOperations.ipynb (unless otherwise specified).

__all__ = ['getCondensedBasic', 'getCondensedLoose', 'getCondensedStrict']

# Cell
#hide
from typing import List

import sys
sys.path.append("..")

from .EditOperations import *

# Cell
def getCondensedBasic(operations: List[EditOperation]) -> List[CompoundOperation]:
    """
    Returns a list of CompoundOperations from the given list of `operations` such that the lengths of the
    input and output lists are equal. I.e. each `CompoundOperation` in the returned list represents just
    one EditOperation.
    """

    compoundOps = []

    for op in operations:
        compoundOps.append(CompoundOperation(op))

    return compoundOps

# Cell
def getCondensedLoose(operations: List[EditOperation]) -> List[CompoundOperation]:
    """
    Returns a list of CompoundOperations from the given list of `operations` such that each `CompoundOperation`
    in the returned list repesents EditOperations that are loosely compatible. This effectively "condenses" the
    given list according to loose compatibility. The length of the returned list is minimized such that it is
    as condensed as possible.
    """

    compoundOps = []

    if len(operations) > 0:

        compoundOps = [CompoundOperation(operations[0])]

        for op in operations[1:]:
            if not compoundOps[-1].addLoose(op):
                compoundOps.append(CompoundOperation(op))

    return compoundOps

# Cell
def getCondensedStrict(operations: List[EditOperation]) -> List[CompoundOperation]:
    """
    Returns a list of CompoundOperations from the given list of `operations` such that each `CompoundOperation`
    in the returned list repesents EditOperations that are strictly compatible. This effectively "condenses" the
    given list according to strict compatibility. The length of the returned list is minimized such that it is as
    condensed as possible.
    """

    compoundOps = []

    if len(operations) > 0:

        compoundOps = [CompoundOperation(operations[0])]

        for op in operations[1:]:
            if not compoundOps[-1].addStrict(op):
                compoundOps.append(CompoundOperation(op))

    return compoundOps