Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created July 31, 2014 01:49
Show Gist options
  • Select an option

  • Save lambda-fairy/bf987a6215a81e47cf9a to your computer and use it in GitHub Desktop.

Select an option

Save lambda-fairy/bf987a6215a81e47cf9a to your computer and use it in GitHub Desktop.
Data.CaseInsensitive and (Co)Traversable
traverse :: (FoldCase s1, FoldCase s2, Functor f) => (s1 -> f s2) -> CI s1 -> f (CI s2)
traverse f = fmap CI.mk . f . CI.original
cotraverse :: (FoldCase s1, FoldCase s2, Functor f) => (f s1 -> s2) -> f (CI s1) -> CI s2
cotraverse f = CI.mk . f . fmap CI.original
-- Examples
concat :: [CI ByteString] -> CI ByteString
concat = cotraverse B.concat
intercalate :: ByteString -> [CI ByteString] -> CI ByteString
intercalate s = cotraverse (B.intercalate s)
inits :: CI ByteString -> [CI ByteString]
inits = traverse B.inits
uncons :: CI ByteString -> Maybe (Word8, CI ByteString)
uncons = getCompose . traverse (Compose . B.uncons)
transpose :: [CI ByteString] -> [CI ByteString]
transpose = undefined -- ??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment