Created
August 16, 2025 06:56
-
-
Save axionbuster/299cf1f6bb3c23e77c7b1f5de1c8695b to your computer and use it in GitHub Desktop.
Revisions
-
axionbuster created this gist
Aug 16, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ {-# LANGUAGE ParallelListComp #-} module Data.Zipper (zipper) where import Data.List import qualified Data.List.NonEmpty as NE -- helper dropLast :: [a] -> [a] dropLast = maybe [] fst . unsnoc zipper :: [a] -> [([a], a, [a])] zipper as = [ (dropLast bs, a, drop 1 cs) | bs <- NE.toList <$> inits1 as | cs <- NE.toList <$> tails1 as | a <- as ] {- ex: zipper [1, 2, 4] = [([],1,[2,4]),([1],2,[4]),([1,2],4,[])] -}