Giter Club home page Giter Club logo

functionaltodolistwithcats's Introduction

To-Do List

This is a little command-line “To-Do List” app, based on the To-Do List app in the book, Learn You A Haskell For Great Good. This version of the app is written with the Cats and Cats-Effect libraries.

The purposes of this application are:

  • To show how to write a small but complete functional programming (FP) application in Scala, in this case using Cats and Cats-Effect
  • To show how to create a single, executable JAR file from a Scala/SBT application with sbt-assembly
  • To show how to create a native executable with GraalVM

The FP part is really the main purpose. Once I created the app I knew that I wanted to use Graal to make it start up faster, so that led to the sbt-assembly need.

Using the application

Once you create the native image, start the application like this:

$ todo

Then you’ll see this prompt:

Command ('h' for help, 'q' to quit)
==>

If you type h you’ll see this help text:

Possible commands
-----------------
add <task>       - add a to-do item
h                - show this help text
rm [task number] - remove a task by its number
v                - view the list of tasks
q                - quit

To add a task, use the add command:

add wake up

Hopefully everything after that is relatively easy to understand.

The source code

If you read my book, Functional Programming, Simplified, hopefully most of the source code will be understandable. The big difference between what I show in the book and this application is the use of the Scalaz library.

In short:

  • ToDoListFIO extends App is where the action starts
  • The mainLoop is the application’s main loop
  • This line of code converts the user’s input into a Command:
cmd   <- getLine.map(Command.parse _)

If you read my book, I hope everything else makes sense.

Creating a single, executable JAR file

To create a single, executable JAR file, using the sbt assembly command, or use the assembly command at the SBT prompt.

GraalVM

To create a native executable with GraalVM will take a little more work on your part, but in short:

  • Install GraalVM on your system
  • cd into this project’s Graal directory
  • I don’t use Graal all the time, so I source the 1setup_graal file to set the necessary GraalVM parameters
  • Then I run the 2compile_graal.sh script to create the todo native image (executable).

The reason for using Graal is to create a native executable image that starts up almost immediately, which is really nice for a command-line application like this.

More information

For more information, see this web page.

All the best,
Alvin Alexander
https://alvinalexander.com

functionaltodolistwithcats's People

Contributors

alvinj avatar

Watchers

James Cloos 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.