packages feed

bookhound-0.1.26.0: src/Bookhound/Utils/Foldable.hs

module Bookhound.Utils.Foldable where

import Bookhound.Utils.Text (indent)
import Control.Monad        (join)
import Data.Foldable        as Foldable (Foldable (toList), find)
import Data.List            (intercalate)
import Data.Maybe           (isJust)


stringify :: Foldable m => String -> String -> String -> Int -> m String -> String
stringify sep start end n xs = start <> indent n str <> end
  where
    str = intercalate sep list
    list = toList xs

findJust :: Foldable t => t (Maybe a) -> Maybe a
findJust ms = join $ Foldable.find isJust ms