Skip to content

Instantly share code, notes, and snippets.

@ncfavier
Last active May 9, 2024 10:53
Show Gist options
  • Save ncfavier/5ba085ccbeca291b73a00b62a4c0ba2f to your computer and use it in GitHub Desktop.
Save ncfavier/5ba085ccbeca291b73a00b62a4c0ba2f to your computer and use it in GitHub Desktop.
module Lib (shortestLongest) where
import Control.Applicative
import Data.Maybe
steps = go []
where
go l (x:xs) = Nothing : go (x:l) xs
go l [] = Just [reverse l] : repeat (Just [])
traverseThen f g = fmap f . traverse g
shortestLongest :: [[[a]]] -> [[a]]
shortestLongest = head
. catMaybes
. getZipList
. traverseThen mconcat (traverseThen (fmap concat . sequenceA)
(ZipList . steps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment