writer-monad

Writer monad and unsequence

你说的曾经没有我的故事 提交于 2020-01-06 18:10:14
问题 I am using the Writer monad to keep track of an error ("collision") flag on arbitrary values (such as Int ). Once the flag is set it is "sticky" and attaches itself to all values produced as a result of any operation with the marked one. Sometimes the collision flag is associated with individual values, sometimes I would like to associate with composite structures such as lists. Of course, once the collision flag is set for a whole list, it also makes sense to assume it is set for an

Validating a sequence of XML elements with Writer monad

不打扰是莪最后的温柔 提交于 2019-12-10 11:18:32
问题 This is a follow-up to my old question. Suppose I need to validate an XML: <a><a1/><a2/><a3/></a> I need to make sure that the root a has children a1 , a2 , and a3 (in this order). I'd like to use a List (instead of scalaz.Validation ) and Writer monad to collect validation errors. So I define a function to validate a sequence of XML elements like this: type Validate = List[Elem] => Writer[List[String], List[Elem]] Now I can add a function to validate the label of an XML element: val label:

Validating a sequence of XML elements with Writer monad

眉间皱痕 提交于 2019-12-06 05:10:00
This is a follow-up to my old question . Suppose I need to validate an XML: <a><a1/><a2/><a3/></a> I need to make sure that the root a has children a1 , a2 , and a3 (in this order). I'd like to use a List (instead of scalaz.Validation ) and Writer monad to collect validation errors. So I define a function to validate a sequence of XML elements like this: type Validate = List[Elem] => Writer[List[String], List[Elem]] Now I can add a function to validate the label of an XML element: val label: String => Validate = ... If I redefine Validate as Kleisli I'll be able to compose the Validate