3 ms·
Just for fun here's the reverse to turn a sequence of booleans into a sequence of integer types (byte,int,long,etc). Note that the length of sequence s must be
by fleitz 16y ago
Just for fun here's the reverse to turn a sequence of booleans into a sequence of integer types (byte,int,long,etc). Note that the length of sequence s must be a multiple of sizeof<'T> times 8
let bitsToBitContainer (s:seq<bool>) : seq<'T> =
let sz = sizeof<'T>*8
s
|> Seq.scan (fun (i,n) x -> (i++,(n<<<1)|||(x&&&1)) (0,0)
|> Seq.filter (fun (i,n) -> i = sz)
|> Seq.map (fun (i,n) -> n)
- mahmud 16y agoI am liking this F# thing. Thanks! :-)