Skip to content

Instantly share code, notes, and snippets.

@jamii

jamii/after.imp Secret

Last active October 12, 2021 23:01
Show Gist options
  • Save jamii/43d49246934839102f6fed35c7b68978 to your computer and use it in GitHub Desktop.
Save jamii/43d49246934839102f6fed35c7b68978 to your computer and use it in GitHub Desktop.
rightmost_child: edits.?edit edit parent~ @ max;
fix rightmost_leaf: edits.?edit edit | edit rightmost_child rightmost_leaf @ max;
prev_sibling: edits.?edit edit parent parent~ .(?sibling edit > sibling) @ max;
prev: edits.?edit edit prev_sibling !! then edit prev_sibling rightmost_leaf else edit parent;
fix position: root, 0 | position ?edit ?pos edit prev~, pos + 1;
edits ?edit (edit position), edit, (edit character)
let rightmost_child = edits (?edit . edit .
(max [edit ~parent])) in
let rightmost_leaf =
fix none (?[rightmost_leaf] .
edits (?edit . edit .
(max [edit | (edit rightmost_leaf rightmost_child)])))) in
let prev_sibling = edits (?edit . edit
(max [(edit parent ~parent) (?sibling . (when (edit > sibling) sibling))])) in
let prev = edits (?edit . edit .
if !!(prev_sibling edit)
([prev_sibling edit] max rightmost_leaf)
(edit parent)) in
let position =
fix none (?[position] .
edits (?edit . edit .
if !(edit parent) then 0 else
(edit prev position) + 1)) in
edits (?edit .
(edit position) . edit . (edit character))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment