Last active
October 10, 2020 08:34
-
-
Save daxfohl/5e606704b13714ca485eeee610680c94 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 addChild updateNode addNode value parent = | |
match withNewChild value parent with | |
| None -> async.Return None | |
| Some (newParent, child) as path -> | |
async { do! addNode child | |
do! updateNode newParent | |
return Some child } | |
let addChildById getNode updateNode addNode logAction value parentId = | |
async { let! parent = getNode parentId | |
let! childOpt = addChild updateNode addNode value parent | |
match childOpt with | |
| None -> return None | |
| Some child -> | |
let action = AddNode { value = value; nodeId = nodeId; leafId = child.id } | |
do! logAction action | |
return Some child.id } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First, I would split the Db functions into their own module instead of passing them as parameters.
Then I would get rid of all other concerns when sequencing your writes. Also, not quite sure what conditions are present for
withNewChild
to return None... maybe whenparent
is None? In that case, you can have one option check at the top instead of embedding them throughout your code.