    {- utilities for simple data types
     -
     - Copyright 2013 Joey Hess <id@joeyh.name>
     -
     - License: BSD-2-clause
     -}

    {-# OPTIONS_GHC -fno-warn-tabs #-}

    module Utility.Data where

    {- First item in the list that is not Nothing. -}
    firstJust :: Eq a => [Maybe a] -> Maybe a
    firstJust :: [Maybe a] -> Maybe a
    firstJust ms :: [Maybe a]
    ms = case (Maybe a -> Bool) -> [Maybe a] -> [Maybe a]
    forall a. (a -> Bool) -> [a] -> [a]
    dropWhile (Maybe a -> Maybe a -> Bool
    forall a. Eq a => a -> a -> Bool
    == Maybe a
    forall a. Maybe a
    Nothing) [Maybe a]
    ms of
    	[] -> Maybe a
    forall a. Maybe a
    Nothing
    	(md :: Maybe a
    md:_) -> Maybe a
    md

    eitherToMaybe :: Either a b -> Maybe b
    eitherToMaybe :: Either a b -> Maybe b
    eitherToMaybe = (a -> Maybe b) -> (b -> Maybe b) -> Either a b -> Maybe b
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either (Maybe b -> a -> Maybe b
    forall a b. a -> b -> a
    const Maybe b
    forall a. Maybe a
    Nothing) b -> Maybe b
    forall a. a -> Maybe a
    Just