//public static void BuildConnectedSubGraph<TVertex, TEdge>(
        //    this IVertexAndEdgeListGraph<TVertex, TEdge> graph,
        //    IMutableVertexAndEdgeListGraph<TVertex, TEdge> subGraph,
        //    IEnumerable<TVertex> entries,
        //    Func<TVertex, TVertex, TEdge> edgeFactory)
        //    where TEdge : IEdge<TVertex>
        //{
        //    var verticiesToKeep = graph.Vertices.Intersect(entries).ToList();
        //    var verticiesToRemove = graph.Vertices.Except(verticiesToKeep).ToList();
        //    DeleteVerticesAndMergeEdges(verticiesToRemove,
        //    foreach (var v in verticiesToRemove)
        //    {

        //    }
        //}


        public static void MergeVertices <TVertex, TEdge>(this IMutableBidirectionalGraph <TVertex, TEdge> graph,
                                                          Func <TVertex, TVertex> groupByPredicate,
                                                          Func <TEdge, TVertex, TEdge> mergeInFunc,
                                                          Func <TVertex, TEdge, TEdge> mergeOutFunc,
                                                          IEqualityComparer <TVertex> comparer = null)
            where TEdge : IEdge <TVertex>
        {
            var grouppedVertices = graph.Vertices.ToLookup(groupByPredicate, comparer).ToList();

            foreach (var x in grouppedVertices)
            {
                graph.MergeVertices(x, x.Key, mergeInFunc, mergeOutFunc, comparer);
            }
        }