module Telescope.Fits.Header.Keyword where
import Data.Fits as Fits hiding (isKeyword)
import Data.List qualified as L
import Data.Text (Text)
import Data.Text qualified as T
lookupKeyword :: Text -> Header -> Maybe Value
lookupKeyword :: Text -> Header -> Maybe Value
lookupKeyword Text
k = (KeywordRecord -> Bool) -> Header -> Maybe Value
findKeyword (Text -> KeywordRecord -> Bool
isKeyword Text
k)
findKeyword :: (KeywordRecord -> Bool) -> Header -> Maybe Value
findKeyword :: (KeywordRecord -> Bool) -> Header -> Maybe Value
findKeyword KeywordRecord -> Bool
p Header
h = do
KeywordRecord
kr <- (KeywordRecord -> Bool) -> [KeywordRecord] -> Maybe KeywordRecord
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
L.find KeywordRecord -> Bool
p (Header -> [KeywordRecord]
getKeywords Header
h)
Value -> Maybe Value
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure KeywordRecord
kr._value
isKeyword :: Text -> KeywordRecord -> Bool
isKeyword :: Text -> KeywordRecord -> Bool
isKeyword Text
k (KeywordRecord Text
k2 Value
_ Maybe Text
_) = Text -> Text
T.toLower Text
k Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Text
T.toLower Text
k2