How can I add all of them using their Int form? I would like to take my List (Maybe Hitpoints) and sum up all their parts to reach a total. And when this numbers goes down between snapshot of memory I want a bool flag of True.
I’m having a hard time reading the Maybe hitpoints value inside the list.
What can I use?
currentDroneLife =
case currentReading.dronesWindow of
Nothing ->
[]
Just dronesWindow ->
case dronesWindow.droneGroupInLocalSpace of
Nothing ->
[]
Just droneGroupInLocalSpace ->
case droneGroupInLocalSpace.drones |> List.map .hitpointsPercent of
[] ->
[]
listHitpoints ->
listHitpoints -- List (Maybe Hitpoints)
droneDamaged =
if currentDroneLife >= botMemoryBefore.currentDroneLife || then
False
else
True
[…]
These operators don’t do anything that we couldn’t achieve with other language elements. They only allow us to write a function differently. We can rewrite any program without them. But, if these are not even strictly necessary, why do we even use them? The reason is that they can help improve the readability of the program code. Just like abbreviations in natural language, they act as shortcuts to consolidate common patterns in our code.
[…]
There are several ways to learn how this operator works.
One way is to look at its definition in the Elm core library here:
When we use it in the form of >>, the first argument goes to the operator’s left and the second to the right. I think this arrangement is the meaning of ‘infix’ in the term ‘infix operator’.
Another way to learn is an interactive exploration in the Elm REPL. Here we get fast feedback to see what happens when we use this operator: