Compares two list and returns how they have changed. Each function internally uses Wu's O(NP) algorithm.
Compares general lists.
diff [ 1, 3 ] [ 2, 3 ]
--> [ Removed 1, Added 2, NoChange 3 ]This will never produce Similar, so you can use never in that branch.
diff a b
|> List.map
(\change ->
case change of
Diff.Added _ ->
1
Diff.Removed _ ->
-1
Diff.NoChange _ ->
0
Diff.Similar _ _ ever ->
never ever
)Compares two text. Considers two lines similar if they are equivalent ignoring spaces.
Giving the following text
a =
"""aaa
bbb
ddd"""
b =
"""zzz
aaa
ccc
ddd"""results in
[ Added "zzz"
, NoChange "aaa"
, Removed "bbb"
, Added "ccc"
, NoChange "ddd"
].
Compares general lists. Allows specifying when two elements are similar.
diff (\l r -> if abs (l - r) < 1 then Just () else Nothing) [ 1, 3 ] [ 2, 3 ]
--> [ Similar 1 2 (), NoChange 3 ]Calculate the diff between two multiline strings.
Options for diffing multiline strings.
Default comparison options.
Ignore leading whitespace when comparing multiline strings.
diffLinesWith (defaultOptions |> ignoreLeadingWhitespace) "a" " a"
--> [ NoChange "a" ]Equivalent to equalIf (\a b -> String.trimLeft a == String.trimLeft b).
Configure when to consider two lines equal.
As an example you can use \l r -> String.trim l == String.trim r to ignore whitespace around lines.
Configure when to consider two lines similar.
This describes how each line has changed and also contains its value.