miniBill/elm-diff/1.0.1

NOTE: the latest version is 1.1.2

Diff

Compares two list and returns how they have changed. Each function internally uses Wu's O(NP) algorithm.

Types

type Change similar a
= Added a
| Removed a
| Similar a a similar
| NoChange a

This describes how each line has changed and also contains its value.

Diffing

diff : List a -> List a -> List (Change Never a)

Compares general lists.

diff [ 1, 3 ] [ 2, 3 ]
--> [ Removed 1, Added 2, NoChange 3 ]
diffLines : String -> String -> List (Change () String)

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"
]

.

diffWith : (a -> a -> Maybe similar) -> List a -> List a -> List (Change similar a)

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 ]