Sounds like what I want. I&#39;ll give it a try. Thanks.<br><br><div><span class="gmail_quote">On 7/18/07, <b class="gmail_sendername">Tillmann Rendel</b> &lt;<a href="mailto:rendel@rbg.informatik.tu-darmstadt.de">rendel@rbg.informatik.tu-darmstadt.de
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Johan Tibell wrote:<br>&gt; I found myself wanting a map that looks at neighboring elements. This is
<br>&gt; where I used explicit recursion the most. Something like this:<br>&gt;<br>&gt; f [] = []<br>&gt; f ((Foo a) : (Bar b) : xs)<br>&gt;&nbsp;&nbsp; | fooBar a b = Foo a : f xs<br>&gt;&nbsp;&nbsp; | otherwise = Bar b : f xs<br>&gt;<br>&gt; This is almost a map. A variation is when filtering and you want some
<br>&gt; look-ahead to make the filtering decision. There&#39;s probably a good way<br>&gt; to do this I&#39;m not aware of.<br><br>If you want to map over all elements, but need to look ahead in the<br>mapped function, you can map over the tails:
<br><br>&nbsp;&nbsp; map&#39; :: ([a] -&gt; b) -&gt; [a] -&gt; b<br>&nbsp;&nbsp; map&#39; f = map f . tails<br><br>f should be something like<br>&nbsp;&nbsp; f (a:b:c:_) = ...<br><br><br>If you want to handle groups of n elements together, producing only one
<br>element per group, you can use unfoldr with splitAt:<br><br>&nbsp;&nbsp; map&#39;&#39; :: Int -&gt; ([a] -&gt; b) -&gt; [a] -&gt; [b]<br>&nbsp;&nbsp; map&#39;&#39; n f =<br>&nbsp;&nbsp;&nbsp;&nbsp; map f . unfoldr (((not . null . fst) `guarding`) . splitAt n)
<br><br>&nbsp;&nbsp; guarding p x = guard (p x) &gt;&gt; return x<br><br><br>If you want to decide in the mapped function how many elements to<br>consume, you can use unfoldr directly.<br><br>&nbsp;&nbsp; Tillmann Rendel<br></blockquote></div>
<br>