<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>I remember discussing this function about 8 or so years ago, in
that it generalises by composition.</p>
<p>Here it is being discussed in Scala in 2012, including the
generalisation by using the composition of functors. Sorry I
couldn't find the earlier Haskell discussions. They are out there
somewhere.<br>
<a class="moz-txt-link-freetext" href="https://groups.google.com/forum/#!msg/scala-user/O_udbztHFHU/mpqPtEkjbb8J">https://groups.google.com/forum/#!msg/scala-user/O_udbztHFHU/mpqPtEkjbb8J</a></p>
<p>However, since the adoption of the lens library since, I have
preferred generalising based on Cons/Empty<br>
<a class="moz-txt-link-freetext" href="https://github.com/qfpl/papa/blob/master/papa-lens-implement/src/Papa/Lens/Implement/Data/Collapse.hs">https://github.com/qfpl/papa/blob/master/papa-lens-implement/src/Papa/Lens/Implement/Data/Collapse.hs</a><br>
</p>
<br>
<div class="moz-cite-prefix">On 29/11/17 14:12, Fumiaki Kinoshita
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAATCwU=Q6xp=OWt0Pz65PAKRE0wdedSMkURzk=8QewRZvwXkag@mail.gmail.com">
<div dir="ltr">
<div>We found this quite useful, but we are not 100% about the
name and documentation.</div>
<div><br>
</div>
<div>-- | Try—in the 'Alternative' sense—to return all the
values in a 'Foldable'</div>
<div>-- container.</div>
<div>--</div>
<div>-- @</div>
<div>-- foldAlt ≡ 'listToMaybe' :: [a] -> 'Maybe' a</div>
<div>-- foldAlt ≡ 'maybeToList' :: 'Maybe' a -> [a]</div>
<div>-- foldAlt ≡ 'MaybeT' . 'return' :: ('Monad' m) =>
'Maybe' a -> 'MaybeT' m a</div>
<div>-- foldAlt ≡ 'Pipes.ListT' . 'Pipes.each' :: ('Monad' m)
=> [a] -> 'Pipes.ListT' m a</div>
<div>-- foldAlt ≡ id :: 'Maybe' a -> 'Maybe' a</div>
<div>-- @</div>
<div>foldAlt :: (Foldable t, Alternative f) => t a -> f a</div>
<div>foldAlt = getAlt . foldMap (Alt . pure)</div>
<div>{-# INLINE foldAlt #-}</div>
<div><br>
</div>
<div>I propose adding this to either `Data.Foldable` or
`Control.Applicative`. Any thoughts?</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Libraries mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libraries@haskell.org">Libraries@haskell.org</a>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a>
</pre>
</blockquote>
<br>
</body>
</html>