<commit_before>module DOM.BrowserFeatures.Detectors
  ( detectBrowserFeatures
  ) where

import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Exception

import qualified Data.Array as Arr
import qualified Data.List as L
import qualified Data.Map as M
import Data.Maybe (maybe)
import Data.Foldable (foldr)
import Data.Traversable (traverse)
import Data.Tuple

import DOM
import Data.BrowserFeatures
import qualified Data.BrowserFeatures.InputType as IT

foreign import _detectInputTypeSupport :: forall e. String -> Eff (dom :: DOM | e) Boolean

detectInputTypeSupport :: forall e. IT.InputType -> Eff (dom :: DOM | e) Boolean
detectInputTypeSupport = _detectInputTypeSupport <<< IT.renderInputType

detectInputTypeSupportMap :: forall e. Eff (dom :: DOM | e) (M.Map IT.InputType Boolean)
detectInputTypeSupportMap = M.fromList <$> traverse (\t -> Tuple t <$> detectInputTypeSupport t) inputTypes
  where
    inputTypes :: L.List IT.InputType
    inputTypes = foldr L.Cons L.Nil IT.allInputTypes

-- | Detect browser features by testing them using the DOM.
detectBrowserFeatures :: forall e. Eff (dom :: DOM | e) BrowserFeatures
detectBrowserFeatures = do
  inputTypeSupportMap <- detectInputTypeSupportMap
  pure { inputTypeSupported : maybe false id <<< flip M.lookup inputTypeSupportMap
       }
<commit_msg>[PR Feedback] Use `fromMaybe` instead of `maybe _ id`<commit_after>module DOM.BrowserFeatures.Detectors
  ( detectBrowserFeatures
  ) where

import Prelude
import Control.Monad.Eff
import Control.Monad.Eff.Exception

import qualified Data.Array as Arr
import qualified Data.List as L
import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import Data.Foldable (foldr)
import Data.Traversable (traverse)
import Data.Tuple

import DOM
import Data.BrowserFeatures
import qualified Data.BrowserFeatures.InputType as IT

foreign import _detectInputTypeSupport :: forall e. String -> Eff (dom :: DOM | e) Boolean

detectInputTypeSupport :: forall e. IT.InputType -> Eff (dom :: DOM | e) Boolean
detectInputTypeSupport = _detectInputTypeSupport <<< IT.renderInputType

detectInputTypeSupportMap :: forall e. Eff (dom :: DOM | e) (M.Map IT.InputType Boolean)
detectInputTypeSupportMap = M.fromList <$> traverse (\t -> Tuple t <$> detectInputTypeSupport t) inputTypes
  where
    inputTypes :: L.List IT.InputType
    inputTypes = foldr L.Cons L.Nil IT.allInputTypes

-- | Detect browser features by testing them using the DOM.
detectBrowserFeatures :: forall e. Eff (dom :: DOM | e) BrowserFeatures
detectBrowserFeatures = do
  inputTypeSupportMap <- detectInputTypeSupportMap
  pure { inputTypeSupported : fromMaybe false <<< flip M.lookup inputTypeSupportMap
       }

{'fraction_non_alphanumeric': 0.08324043106651802, 'fraction_numerical': 0.0, 'mean_word_length': 4.776824034334764, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1067807', 'n_tokens_mistral': 775, 'n_tokens_neox': 764, 'n_words': 256}