I have just discovered that you can use guards in the `case` pattern

Might be useful for other Daml-ers as well.

Source: dablchat/V3.daml at e648049b6d74805ed85154518ab7a89194326d2a · digital-asset/dablchat · GitHub

5 Likes

Great tip, here’s the text version for easier reading / searching

case optAliasCid of
    Some cid | alias /= "" -> do
        newCid <- exercise cid SelfAlias_Rename with newAlias = alias
        return $ Some newCid
    Some cid | alias == "" -> do
        archive cid
        return None
    None | alias /= "" -> do
        cid <- create SelfAlias with ..
        return $ Some cid
    _ -> return None
2 Likes