
2 Apr
2007
2 Apr
'07
1:20 p.m.
Bryan O'Sullivan wrote:
unpackBits :: Bits b => [(a, b)] -> b -> [a]
unpackBits mapping bits = foldl' unpack [] mapping where unpack acc (k, v) | bits .&. v == 0 = acc | otherwise = k:acc
Of course, this is stricter than it needs to be, and should use foldr instead of foldl'. But I hope that the idea is useful nevertheless :-)