Created
January 7, 2019 17:32
-
-
Save sslotsky/5e73b330fa5be38972f2baf50f61ab02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let insert = site => { | |
let (leftSide, rightSide) = sites^ |> List.partition(s => s.left <= site.left); | |
let (overlap, rest) = rightSide |> List.partition(s => s.left <= site.right); | |
let rightSide = switch(overlap) { | |
| [] => [site, ...rightSide] | |
| _ => let closest = overlap->List.rev->List.hd; [site->connectRight(closest), ...rest] | |
} | |
let site = rightSide->List.hd; | |
let leftSide = switch (leftSide->List.rev) { | |
| [s, ...rest] when s.right >= site.left => [s->connectRight(site), ...rest]->List.rev | |
| _ => leftSide->List.append([site]) | |
}; | |
sites := switch (rightSide->List.tl) { | |
| tail => leftSide->List.append(tail) | |
| exception Failure(_) => leftSide | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment