packages feed

tools-yj 0.1.0.25 → 0.1.0.26

raw patch · 3 files changed

+44/−2 lines, 3 filesdep +bytestringPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependencies added: bytestring

API changes (from Hackage documentation)

+ Data.Bits.ToolsYj: bitsToBits :: (Bits a, Bits b) => Int -> a -> b
+ Data.ByteString.ToolsYj: fromBits :: Bits b => b -> ByteString
+ Data.ByteString.ToolsYj: fromBits' :: FiniteBits b => b -> ByteString
+ Data.ByteString.ToolsYj: toBits :: Bits b => ByteString -> b
+ Data.ByteString.ToolsYj: toBits' :: FiniteBits b => ByteString -> Maybe b

Files

src/Data/Bits/ToolsYj.hs view
@@ -1,7 +1,8 @@ {-# OPTIONS_GHC -Wall -fno-warn-tabs #-} -module Data.Bits.ToolsYj (checkBits, bitsList) where+module Data.Bits.ToolsYj (bitsToBits, checkBits, bitsList) where +import Control.Arrow import Data.Bits  checkBits :: Bits bs => bs -> bs -> Bool@@ -10,3 +11,7 @@ bitsList :: FiniteBits bs => bs -> [bs] bitsList bs = 	filter (/= zeroBits) $ map ((bs .&.) . bit) [0 .. finiteBitSize bs - 1]++bitsToBits :: (Bits a, Bits b) => Int -> a -> b+bitsToBits n b = foldl setBit zeroBits+	. map fst . filter snd $ map (id &&& testBit b) [0 .. n - 1]
+ src/Data/ByteString/ToolsYj.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE ImportQualifiedPost #-}+{-# LANGUAGE BlockArguments, OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}+{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}++module Data.ByteString.ToolsYj (++	fromBits, fromBits', toBits, toBits'++	) where++import Data.Bits+import Data.Bits.ToolsYj+import Data.Bool+import Data.ByteString qualified as BS++fromBits :: Bits b => b -> BS.ByteString+fromBits = BS.unfoldr \b ->+	bool Nothing (Just (bitsToBits 8 b, b `shiftR` 8)) (b /= zeroBits)++fromBits' :: FiniteBits b => b -> BS.ByteString+fromBits' b0 = go (finiteBitSize b0 `div` 8) b0+	where+	go 0 _ = ""+	go n b = bitsToBits 8 b `BS.cons` go (n - 1) (b `shiftR` 8)++toBits :: Bits b => BS.ByteString -> b+toBits = BS.foldr (\b s -> bitsToBits 8 b .|. s `shiftL` 8) zeroBits++toBits' :: forall b . FiniteBits b => BS.ByteString -> Maybe b+toBits' bs = bool+	Nothing+	(Just $ BS.foldr (\b s -> bitsToBits 8 b .|. s `shiftL` 8) zeroBits bs)+	(8 * BS.length bs <= finiteBitSize @b undefined)
tools-yj.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           tools-yj-version:        0.1.0.25+version:        0.1.0.26 synopsis:       Tribial tools description:    Please see the README on GitHub at <https://github.com/YoshikuniJujo/tools-yj#readme> category:       Tools@@ -31,6 +31,7 @@       Control.Monad.ToolsYj       Data.Bits.ToolsYj       Data.Bool.ToolsYj+      Data.ByteString.ToolsYj       Data.Either.ToolsYj       Data.Function.ToolsYj       Data.IORef.ToolsYj@@ -50,6 +51,7 @@   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints   build-depends:       base >=4.7 && <5+    , bytestring <1     , containers <1     , data-default <1     , mono-traversable <2@@ -69,6 +71,7 @@   ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N   build-depends:       base >=4.7 && <5+    , bytestring <1     , containers <1     , data-default <1     , mono-traversable <2