I really just need something like
forEach (mkView list) $ \back (elt:forth) -> do
case back of [] -> print "we are first"; (b:_) -> print ("prev elt is " <> show b)
case forth of [] -> print "we are last"; (f:_) -> print ("next elt is " <> show f)
doThing elt etc
but most of the stuff I find when I Hackage search for Zipper seems either very generic or non-total
Do people just roll their own when they have such simple needs?
Are you looking for something like this?
diagonally :: ([x] -> [x] -> y) -> [x] -> [y]
diagonally f xs = zipWith f (inits xs) (tails xs)
You can also use zipWithM for applicative actions:
diagonallyM :: (Applicative m) => ([x] -> [x] -> m y) -> [x] -> m [y]
diagonallyM f xs = zipWithM f (inits xs) (tails xs)
4 Likes
Oh that was quite concise, nice 
Though I needed a reverse in there
diagonally :: ([x] -> [x] -> y) -> [x] -> [y]
diagonally f xs = zipWith f (map reverse $ inits xs) (tails xs)
since I want to look at the element(s) immediately preceding the “focus”:
λ> diagonally (\a b -> (headMay a,headMay b)) [1..4]
[(Nothing,Just 1),(Just 1,Just 2),(Just 2,Just 3),(Just 3,Just 4),(Just 4,Nothing)]