GithubHelp home page GithubHelp logo

helensoniega / pie Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zainab-ali/pie

0.0 0.0 0.0 154 KB

A tutorial on functional Scala, cats effect and fs2

License: Apache License 2.0

Scala 100.00%

pie's Introduction

Pie

This is a tutorial on functional programming in Scala with cats, cats-effect and fs2.

Over the course of the tutorial you'll learn about:

  • Algebraic data types
  • Structural recursion
  • Typeclasses
  • Semigroups, monoids, functors and monads
  • Monad transformers
  • Free encodings
  • Effects and evaluation

Getting Started

  1. Type sbt to enter the sbt console.
  2. Run the application with run 12. This should draw a 12 inch pizza with a single olive (you'll need to use your imagination here).

Take a look inside the pie.PizzaShop to see what gets run.

Algebraic Data Types

Make sure you're familiar with Modelling Data with Traits

Basic validation with the Either datatype

Take a look at the tests in ValidateSizeTest. Write a function validateSize that:

  • takes a pizza size as an argument
  • evaluates to either a pizza or an error

The error must be one of:

  • NegativeSize
  • PizzaTooBig
  • PizzaTooSmall

Discuss: Should this really evaluate to a pizza? Could there be a better type to use.

Error handling with the Either datatype

Write a function correction. As an argument, it should take in an error.

  • If the error is a PizzaTooBig error, it evaluates to a 16 inch pizza
  • If the error is a PizzaTooSmall error, it evaluates to a 3 inch pizza
  • If the error is none of the above, it evaluates to that same error

Validation with the cats Validated datatype

Write a function validateSauce that:

  • takes a sauce name as an argument
  • evaluates to either Bechamel, Tomato or a StrangeSauce error

Use a Validated to evaluate both vaildateSize and validateSauce.

pie's People

Contributors

zainab-ali avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.