indicatrix / elm-input-extra / Diff

NOTES: This is a copy of https://github.com/avh4/elm-diff/blob/master/src/Diff.elm with an upgrade to Elm 0.18. I need to copy it here since it's not upgraded to Elm 0.18 yet. Replace this with package dependency once it's upgraded to Elm 0.18. Functions to compare strings to produce a list of changes. This is an implementation of the Hunt-McIlroy diff algorithm.

Types and Constructors


type Change
    = NoChange String
    | Changed String String
    | Added String
    | Removed String

Diffing strings

diffChars : String -> String -> List Change

Diffs two strings, comparing character by charater.

diffChars "abc" "aBcd"
    == [ NoChange "a", Changed "b" "B", NoChange "c", Added "d" ]

diffLines : String -> String -> List Change

Diffs two strings, comparing line by line.

original = """Brian
Sohie
Oscar
Stella
Takis
"""

changed = """BRIAN
Stella
Frosty
Takis
"""

diffLines original changed
  == [ Changed "Brian\nSohie\nOscar\n" "BRIAN\n"
      , NoChange "Stella\n"
      , Added "Frosty\n"
      , NoChange "Takis\n"
      ]