Post A92pMbR1P2rzAS1sau by dpwiz@mastodon.social
 (DIR) More posts by dpwiz@mastodon.social
 (DIR) Post #A8zrmfUCa0hrhCC4bw by hyperrealgopher@fosstodon.org
       2021-07-06T01:39:37Z
       
       0 likes, 0 repeats
       
       #haskell: sometimes you gotta manipulate and shuffle around some monads and functors/applicatives like a 4D Russian nesting doll.`traverse` is a function that really shows that off. Picture related. Using `traverse` with `Either` and `Maybe` while inside a parser monad.
       
 (DIR) Post #A8zs3KPIClZPF6qEsK by hyperrealgopher@fosstodon.org
       2021-07-06T01:42:37Z
       
       0 likes, 0 repeats
       
       What's happening in the code:`traverse` is a handy function, especially when used with `Either` to escape failing inside a Maybe monad.
       
 (DIR) Post #A91EsbTGudoP5JWA8O by dpwiz@mastodon.social
       2021-07-06T17:33:06Z
       
       0 likes, 0 repeats
       
       @hyperrealgopher And this is why I prefer do notation over applicative.But at least the body of that case can be extracted from the expression.And with for instead of traverse `makeRenderAs` could be a \case in a final position.
       
 (DIR) Post #A91pad1o57JP0NxmrI by dpwiz@mastodon.social
       2021-07-06T17:39:17Z
       
       0 likes, 0 repeats
       
       @hyperrealgopher```haskell(o .:? "renderAs" >>= renderAsP)renderAsP = traverse \case  String "menu" ->    pure GopherTypeMenu  wtf ->    unexpected wtf```It is sometimes beneficial to try `for` instead of `traverse`.
       
 (DIR) Post #A91padToOziIPF49Vg by hyperrealgopher@fosstodon.org
       2021-07-07T00:24:25Z
       
       0 likes, 0 repeats
       
       @dpwiz I didn't want to have `makeRenderAs` handle the type plumbing of the `Maybe`, was my rationale. That is an interesting way of handling the issue, though (putting everything in `traverse`). Thank you for sharing!
       
 (DIR) Post #A921sFNnvoCoKjQ6vQ by hyperrealgopher@fosstodon.org
       2021-07-07T02:42:05Z
       
       0 likes, 0 repeats
       
       @dpwiz also, I've never used `for`. I will look into that.
       
 (DIR) Post #A92pMbR1P2rzAS1sau by dpwiz@mastodon.social
       2021-07-07T11:56:35Z
       
       0 likes, 0 repeats
       
       @hyperrealgopher I regularly use Foldable, Traversable and other well-known instances of Maybe and Either. It is liberating to think in instance methods instead of making a fuss about some stuff being a Monad.