-
-
Save samdvr/4e140780ffc23b6740696d5864718e81 to your computer and use it in GitHub Desktop.
with example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule RetweetCalculator do | |
def calculate_total_retweets(user_id) do | |
with {:ok, handle} <- twitter_handle_for(user_id), | |
{:ok, tweets} <- all_tweets_for(handle), | |
do: { :ok, sum_retweets_for(tweets) } | |
end | |
defp twitter_handle_for(user_id) do | |
# implementation | |
{:ok, handle} | |
end | |
defp all_tweets_for(user) do | |
# implementation | |
{:ok, []} | |
end | |
defp sum_retweets_for(tweets) do | |
tweets | |
|> Enum.map(fn(tweet) -> tweet.retweets end) # => [2,3,5,7] | |
|> Enum.sum # => 17 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment