Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert a byte sequence to a float sequence F# (seq<seq<byte> -> seq<seq<float>)

Tags:

f#

I'm a newbie to F# and currently wondering how to convert a byte sequence of sequences to a float sequence of sequences

seq< seq< byte> -> seq< seq< float>

So I have this following byte sequence

let colourList = seq[ seq[10uy;20uy;30uy]; seq[50uy;60uy;70uy] ]

I have tried using

colourList |> Seq.map System.Double.Parse

to create a new sequence with float elements but it does not work. Can someone help me please? I've been stuck on this one for days.

like image 967
mickey.1 Avatar asked Feb 03 '26 07:02

mickey.1


1 Answers

System.Double.Parse is function that maps string into float. What you are looking for here is a function that maps byte -> float. That function is named: float.

One answer could be this:

let colourList  = [[10uy;20uy;30uy]; [50uy;60uy;70uy]]
let floatList   = List.map (List.map float) colourList

We use .map operations to apply a map function to each element in a sequences.

Since you have two nested sequences it seems logical that we need two nested .map operations to do the mapping you need.

List.map float is a function that maps the inner sequence: byte list -> float list

We apply this function to the outer sequence using List.map (List.map float)to achieve: byte list list -> float list list

like image 94
Just another metaprogrammer Avatar answered Feb 06 '26 04:02

Just another metaprogrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!