module FULE.Internal.Util where

import Data.Maybe


collapseTo :: ([a] -> b) -> [Maybe a] -> Maybe b
collapseTo :: forall a b. ([a] -> b) -> [Maybe a] -> Maybe b
collapseTo [a] -> b
f [Maybe a]
ms =
  case [Maybe a] -> [a]
forall a. [Maybe a] -> [a]
catMaybes [Maybe a]
ms of
    [] -> Maybe b
forall a. Maybe a
Nothing
    [a]
ls -> b -> Maybe b
forall a. a -> Maybe a
Just ([a] -> b
f [a]
ls)

getMaxSize :: [Maybe Int] -> Maybe Int
getMaxSize :: [Maybe Int] -> Maybe Int
getMaxSize = ([Int] -> Int) -> [Maybe Int] -> Maybe Int
forall a b. ([a] -> b) -> [Maybe a] -> Maybe b
collapseTo [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum

getTotalSize :: [Maybe Int] -> Maybe Int
getTotalSize :: [Maybe Int] -> Maybe Int
getTotalSize = ([Int] -> Int) -> [Maybe Int] -> Maybe Int
forall a b. ([a] -> b) -> [Maybe a] -> Maybe b
collapseTo [Int] -> Int
forall a. Num a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum