Last active
May 9, 2024 10:53
-
-
Save ncfavier/5ba085ccbeca291b73a00b62a4c0ba2f to your computer and use it in GitHub Desktop.
Solutions to https://github.com/effectfully-ou/haskell-challenges. See https://github.com/ncfavier/haskell-challenges
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 characters
| 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