Skip to content

Commit

Permalink
Use the Position type in the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
buth committed Jan 22, 2023
1 parent f19c4e7 commit a50a595
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ using a callback provided to the `Diff` method.
import "github.com/buth/diff"

type edit[T comparable] struct {
start, end int
start, end diff.Position
replacement []T
}

func listOfEdits[T comparable](dst, src []T) []edit[T] {
var edits []edit[T]
diff.Diff(dst, src, nil, func(start, end int, replacement []T) {
diff.Diff(dst, src, nil, func(start, end diff.Position, replacement []T) {
edits = append(edits, edit[T]{
start: start,
end: end,
Expand All @@ -44,9 +44,9 @@ func applyEdits[T comparable](src []T, edits []edit[T]) []T {

i := 0
for _, edit := range edits {
dst = append(dst, src[i:edit.start]...)
dst = append(dst, src[i:edit.start.Index]...)
dst = append(dst, edit.replacement...)
i = edit.end
i = edit.end.Index
}

return append(dst, src[i:]...)
Expand Down

0 comments on commit a50a595

Please sign in to comment.