The flip side of Chirashi, simply storing sum type values and retrieving them by using the constructor name as a test value, by using Generic.Rep
to get constructor names from a sum type definition.
Works by subclassing Error.
data ErrorGenericSum
= Apple
| Banana { info :: String }
| Cherry Int Int Int
derive instance genericErrorGenericSum :: GR.Generic ErrorGenericSum _
main = do
let
knownGenericSum :: ErrorGenericSum
knownGenericSum = Banana { info: "hello" }
knownError = Bibimbap.mkGenericSumError knownGenericSum
resultKnownError = Bibimbap.readGenericSum knownError
Assert.assertEqual
{ expected: Just knownGenericSum
, actual: resultKnownError
}
See tests for more examples.