/shopping-cart-tagless-final

Shopping cart implementation using tagless final pattern with cats effect

Primary LanguageScala

Instructions for the assignment

  1. Clone this repository on your machine.
  2. Use your IDE of choice to complete the assignment.
  3. When you are finished with the solution and have pushed it to the repo, you can submit the assignment here.

About the task

We’ll be using a simple shopping cart, similar to those used by e-commerce websites, as the domain for this problem.

There’s no time limit for this task. We expect that you can give a representative piece of code in 1-2 hours.

Tips on what we’re looking for

1. Test coverage

Your solution should:

  • be developed 'test-first'
  • have good unit tests
  • cover common paths
  • be self-contained and not rely on external systems when running tests. Use fakes/ mocks/ stubs as you see fit.
  • in a "real" project integration tests may use a network could run over the network but this is not required for this assessment.

2. Simplicity

We value simplicity as an architectural virtue and a development practice. Solutions should reflect the difficulty of the assigned task, and shouldn’t be overly complex. We prefer simple, well tested solutions over clever solutions.

Please avoid:

  • A web, desktop, command line or any other kind of app
  • Unnecessary layers of abstraction
  • Unnecessary patterns/ architectural features that aren’t called for

Your code needs only to be driven by tests and can extend IOApp

3. Self-explanatory code

The solution you produce must speak for itself. Multiple paragraphs explaining the solution is a sign that the code isn’t straightforward enough to understand on its own.

4. Dealing with ambiguity

If there’s any ambiguity, please add this in a section at the bottom of the README. You should also make a choice to resolve the ambiguity.

5. An understanding of functional programming

The solution should demonstrate the use of functional programming concepts, in particular, the use of immutable data structures, referential transparency, and the use of the monads in dealing with effects.

We often use Cats in our projects, so we've provided all the boilerplate and dependencies in this template project. However, we are more interested in your use of functional programming techniques than the use of a library, so feel free to deviate from what we provide here.

Begin the task

Create a shopping cart package that facilitates 2 basic capabilities.

  1. Add a product to the cart

    1. Specifying the product name and quantity
    2. Use the product name to discover the price from the Product API specified below
    3. Cart state (totals, etc.) must be available
  2. Calculate the state:

    1. Cart subtotal (sum of price for all items)
    2. Tax payable (charged at 12.5% on the subtotal)
    3. Total payable (subtotal + tax)
    4. Totals should be rounded up where required

Product API

Base URL: https://equalexperts.github.io/

View Product: GET /backend-take-home-test-data/{product}.json

Available products

  • cheerios
  • cornflakes
  • frosties
  • shreddies
  • weetabix

Example

The below is a sample with the correct values you can use to confirm your calculations

Inputs

  • Add 1 × cornflakes @ 2.52 each
  • Add another 1 x cornflakes @2.52 each
  • Add 1 × weetabix @ 9.98 each

Results

  • Cart contains 2 x cornflakes
  • Cart contains 1 x weetabix
  • Subtotal = 15.02
  • Tax = 1.88
  • Total = 16.90

Resolving ambiguity

  • Can price change ?
    • on the assumption it can change:
      • prices are not cached as price accuracy is considered more important than performance optimization;
      • if performance (or cost) for calling an external service to check the price becomes a problem, a cache could be added:
        • an eventual cache implementation would need to make sure it is kept in sync with price updates (by either subscribing to price updates, if the price service supports it, or by pulling prices on a scheduled basis);