Developing a functional pipe for the average score function

First, let's recap on how the average_score function was written:

function average_score(n = 10)    story_ids = fetch_top_stories()    println(now(), " Found ", length(story_ids), " stories")    top_stories = [fetch_story(id) for id in story_ids[1:min(n,end)]]    println(now(), " Fetched ", n, " story details")    avg_top_scores = mean(s.score for s in top_stories)    println(now(), " Average score = ", avg_top_scores)    return avg_top_scoresend

Although the code looks quite decent and simple to understand, let me point out some potential issues:

  • The top stories are retrieved via array comprehension syntax. The logic is a little busy and we won't be able to test this part of the code independently ...

Get Hands-On Design Patterns and Best Practices with Julia now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.