F82d5648a23607ee54ad2d56952e625a

Is there a nicer way to 'convert' a list of strings to a list of floats?

ListOfFloats = [ Y || {Y,_} <- [string:to_float(X) || X <- ListOfStrings]].

Refactorings

No refactoring yet !

D41d8cd98f00b204e9800998ecf8427e

Ferd

January 7, 2010, January 07, 2010 20:34, permalink

No rating. Login to rate!

The following might save you a few traversals at the cost of cleaner code.

[ F || X <- ListOfStrings, {F,_} <- [string:to_float(X)]]
Eff7d5dba32b4da32d9a67a519434d3f

df

October 14, 2010, October 14, 2010 05:59, permalink

No rating. Login to rate!

dfd

ListOfFloats = dfdf
D41d8cd98f00b204e9800998ecf8427e

Mazen Harake

March 29, 2011, March 29, 2011 19:48, permalink

No rating. Login to rate!

This is more correct imho.

ListOfFloats = [ element(1,string:to_float(X)) || X <- ListOfStrings ].

Your refactoring





Format Copy from initial code

or Cancel