/// <summary>Returns the result of stacking <paramref name="mergePath"/> onto <paramref name="this"/></summary> public static Maybe <IDirectedPath> MergePaths(this IDirectedPath @this, IDirectedPath mergePath) { if (@this == null || mergePath == null) { return(null); } while (mergePath.PathSoFar != null) { var hexside = mergePath.PathStep.HexsideExit; var cost = mergePath.TotalCost - (mergePath = mergePath.PathSoFar).TotalCost; @this = @this.AddStep(mergePath.PathStep.Coords, hexside, cost); } return(@this.ToMaybe()); }