Scala and Data Pipeline – Phone Bill Calculation Example

Scala and Data Pipeline - Phone Bill Calculation Example

Earlier this year a friend sent me a video showing how he implemented a phone bill calculation challenge using Scala. I took a stab at it using Java + Data Pipeline and below is what I came up with.

How about you? How would you code this using your favourite language or framework?

The Scala Approach

You can watch Ervin’s walk-through of his Scala solution:

You can also read the original requirements for yourself.

Phone Bill Calculator in Scala

The Data Pipeline Approach

Here’s the Data Pipeline code I put together.

  1. It uses a CSVReader to load the data from a string.
  2. It then uses a series of TransformingReaders to convert the duration to seconds and conditionally calculate the price depending on whether the duration is over 5 minutes or not.
  3. Next it uses a GroupByReader to sum the price and duration and to count the calls before sorting them and dropping the one with the highest duration.
  4. Finally, another GroupByReader is used to sum all the prices together to find and return the grand total.

What’s your Approach?

I’d love to see other approaches in any programming language or framework, but other Scala and Java approaches would be great to see.

Happy Coding!

About Dele Taylor

We make Data Pipeline — a lightweight ETL framework for Java. Use it to filter, transform, and aggregate data on-the-fly in your web, mobile, and desktop apps. Learn more about it at

2 thoughts on “Scala and Data Pipeline – Phone Bill Calculation Example

  • By Devin McIntyre - Reply

    Great post! I wrote up a response solution in vanilla Java if you’d like to take a look!

    • By Dele Taylor - Reply

      Thanks for the pure Java approach Devin. Glad you had fun 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">