I’m doing a bit of math between ints and floats, and converting ints to floats seems to take up most of my screen. For instance, these three lines:
// The furthest the user can hit
let maxDistanceIndex = fairway
-> A.findIndex(it => Int.toFloat(it.yards) <= maxDistance)
// The LIVE value from the selector, from 0-1
let (yPercent, setYPercent) =
React.useState(() => Int.toFloat(maxDistanceIndex) /. Int.toFloat(itemCount))
// the LIVE selection
let activeSelection = (Int.toFloat(itemCount) *. yPercent)
-> Math.round
All this casting is making some simple maths a bit more difficult to read, and I’m wondering if this is just how it’s meant to be done. Or is there an easier/recommended way?
// The furthest the user can hit
let maxDistanceIndex = fairway
-> A.findIndex(it => float(it.yards) <= maxDistance)
// The LIVE value from the selector, from 0-1
let (yPercent, setYPercent) =
React.useState(() => float(maxDistanceIndex) /. float(itemCount))
// the LIVE selection
let activeSelection = (float(itemCount) *. yPercent)
-> Math.round
The helper name could be even shorter, of course, e.g. f.