private static void _distinct_internal <T>(this IOperationController controller, object key,
                                                   Func <T, T, IOperation> generateMergedOperation)
            where T : class, IMergeableOperation
        {
            var operations = controller.Operations.ToList();

            var mergeable = operations
                            .OfType <T>()
                            .Where(x => x.MergeJudge.GetMergeKey() == key)
                            .ToArray();

            var first = mergeable.FirstOrDefault();
            var last  = mergeable.LastOrDefault();

            if (first is null || last is null)
            {
                return;
            }

            var lastIndex = 0;

            foreach (var operation in mergeable)
            {
                lastIndex = operations.IndexOf(operation);
                operations.RemoveAt(lastIndex);
            }

            var newOperation = generateMergedOperation(first, last);

            operations.Insert(lastIndex, newOperation);

            controller.Flush();
            operations.ForEach(x => controller.Push(x));
        }