Reduce on FQL 10 does not have a way to set the initial value

I want to calculate how many points a team member has given in the day. The query below works well if the user already has given any points but it returns null in case the user didn’t given a point in the day.

let team = teams.byId(123)
let giver = team_members
  .byTeam(team)
  .where(.user.email == "test.com").first()
let givenPointsToday = given_points
  .byGiver(giver)
  .where(.team == team && .date == Date.today())
  .reduce((sum, givenPoint) => sum + givenPoint.amount)

So, to achieve that I have to run some extra code inside. of the query which is not the best… I’m windering if this is something that could be added again in FQL. Thank you!

I found the fold() is the function that I was looking for.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.