Skip to content

Instantly share code, notes, and snippets.

@snoble
Created April 6, 2021 20:14
Show Gist options
  • Save snoble/b8cb38a88a52338f59ba43b12af5dda9 to your computer and use it in GitHub Desktop.
Save snoble/b8cb38a88a52338f59ba43b12af5dda9 to your computer and use it in GitHub Desktop.
An add operation that appears to be a semilatice
addLists : (a -> a -> Order) -> List a -> List a -> List a
addLists compareFn lst1 lst2 =
case ( lst1, lst2 ) of
( _, [] ) ->
lst1
( [], _ ) ->
lst2
( h1 :: t1, h2 :: t2 ) ->
case compareFn h1 h2 of
EQ ->
h1 :: addLists compareFn t1 t2
GT ->
h1 :: addLists compareFn t1 lst2
LT ->
h2 :: addLists compareFn lst1 t2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment