3
votes

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.

1

1 Answers

4
votes

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