<commit_before>{-# LANGUAGE Rank2Types #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Data.Typeable.Lens
-- Copyright   :  (C) 2012 <NAME>
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  experimental
-- Portability :  Rank2Types
--
----------------------------------------------------------------------------
module Data.Typeable.Lens
  ( _cast
  , _gcast
  ) where

import Control.Applicative
import Control.Lens
import Data.Typeable
import Unsafe.Coerce as Unsafe

-- | A 'Simple' 'Traversal' for working with a 'cast' of a 'Typeable' value.
_cast :: (Typeable a, Typeable b) => Simple Traversal a b
_cast f a = case cast a of
  Just b -> Unsafe.unsafeCoerce <$> f b
  Nothing -> pure a

-- | A 'Simple' 'Traversal' for working with a 'cast' of a 'Typeable' value.
_gcast :: (Typeable a, Typeable b) => Simple Traversal (c a) (c b)
_gcast f a = case gcast a of
  Just b -> Unsafe.unsafeCoerce <$> f b
  Nothing -> pure a
<commit_msg>gcast<commit_after>{-# LANGUAGE Rank2Types #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Data.Typeable.Lens
-- Copyright   :  (C) 2012 <NAME>
-- License     :  BSD-style (see the file LICENSE)
-- Maintainer  :  <NAME> <<EMAIL>>
-- Stability   :  experimental
-- Portability :  Rank2Types
--
----------------------------------------------------------------------------
module Data.Typeable.Lens
  ( _cast
  , _gcast
  ) where

import Control.Applicative
import Control.Lens
import Data.Typeable
import Unsafe.Coerce as Unsafe

-- | A 'Simple' 'Traversal' for working with a 'cast' of a 'Typeable' value.
_cast :: (Typeable a, Typeable b) => Simple Traversal a b
_cast f a = case cast a of
  Just b -> Unsafe.unsafeCoerce <$> f b
  Nothing -> pure a

-- | A 'Simple' 'Traversal' for working with a 'gcast' of a 'Typeable' value.
_gcast :: (Typeable a, Typeable b) => Simple Traversal (c a) (c b)
_gcast f a = case gcast a of
  Just b -> Unsafe.unsafeCoerce <$> f b
  Nothing -> pure a

{'fraction_non_alphanumeric': 0.25729316116690576, 'fraction_numerical': 0.005738880918220947, 'mean_word_length': 1.770860927152318, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '1174606', 'n_tokens_mistral': 673, 'n_tokens_neox': 646, 'n_words': 222}