I need to match a field that may be optional. I figured I could use the ‘plural’ versions of selectors (e.g. texts) plus something like listToMaybe to ‘safely’ match only the first occurrence of an element, but this does not work as expected.
To my great surprise, texts also fails matching anything if there are 0 elements, which I did not expect. I expected it to return an empty list (like ‘many’ in Parsec). In keeping with the principle of least surprise, I would recommend changing the semantics of these matchers.
I need to match a field that may be optional. I figured I could use the ‘plural’ versions of selectors (e.g.
texts
) plus something likelistToMaybe
to ‘safely’ match only the first occurrence of an element, but this does not work as expected.To my great surprise,
texts
also fails matching anything if there are 0 elements, which I did not expect. I expected it to return an empty list (like ‘many’ in Parsec). In keeping with the principle of least surprise, I would recommend changing the semantics of these matchers.