All Projects → calvinlfer → tagless-final-example

calvinlfer / tagless-final-example

Licence: other
An example of how to create services using tagless final

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to tagless-final-example

freAST
Fast, simple Free Monads using ScalaMeta macro annotations. Port of Freasy-Monad.
Stars: ✭ 14 (-44%)
Mutual labels:  monad
apropos
Fast strong typed 'Either' data structure for typescript and flow
Stars: ✭ 20 (-20%)
Mutual labels:  monad
mercator
Automatic typeclass-based abstraction over monad-like types
Stars: ✭ 54 (+116%)
Mutual labels:  monad
tagless-final-jam
Workshop On Tagless Final Interpreters
Stars: ✭ 37 (+48%)
Mutual labels:  tagless-final
monas
🦋 Scala monads for javascript
Stars: ✭ 21 (-16%)
Mutual labels:  monad
tfModelServing4s
Reasonable API for serving TensorFlow models using Scala
Stars: ✭ 29 (+16%)
Mutual labels:  tagless-final
sealed-monad
Scala library for nice business logic oriented, for-comprehension-style error handling
Stars: ✭ 16 (-36%)
Mutual labels:  monad
harmony
C++ Monadologie
Stars: ✭ 26 (+4%)
Mutual labels:  monad
ScrapeM
A monadic web scraping library
Stars: ✭ 17 (-32%)
Mutual labels:  monad
f
a library to write async vert.x code similar as using java syntax
Stars: ✭ 22 (-12%)
Mutual labels:  monad
workshop-edsl-in-typescript
Code template for workshop "Building eDSLs in functional TypeScript"
Stars: ✭ 49 (+96%)
Mutual labels:  tagless-final
alea
Coq library for reasoning on randomized algorithms [maintainers=@anton-trunov,@volodeyka]
Stars: ✭ 20 (-20%)
Mutual labels:  monad
result17
A rust like Result type for modern C++
Stars: ✭ 13 (-48%)
Mutual labels:  monad
30minLearningJavaScriptMonad
30分でわかるJavaScriptプログラマのためのモナド入門
Stars: ✭ 15 (-40%)
Mutual labels:  monad
ts-belt
🔧 Fast, modern, and practical utility library for FP in TypeScript.
Stars: ✭ 439 (+1656%)
Mutual labels:  monad
bullet-scala
A monadic library to resolve object relations with the aim of avoiding the N+1 query problem.
Stars: ✭ 53 (+112%)
Mutual labels:  monad
zenith
⚡ Functional Scala HTTP server, client, and toolkit.
Stars: ✭ 15 (-40%)
Mutual labels:  tagless-final
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (+132%)
Mutual labels:  monad
php-slang
The place where PHP meets Functional Programming
Stars: ✭ 107 (+328%)
Mutual labels:  monad
fpEs
Functional Programming for EcmaScript(Javascript)
Stars: ✭ 40 (+60%)
Mutual labels:  monad

An example service built on Tagless Final

Medium article

A small example demonstrating how to make use of Tagless Final in order to delay the decision of choosing a concrete effect (like Future or Task) till the end and in order to provide easily swappable implementation of effects.

Here, we delay the implementation of OrderRepository to the "end of the world". The OrderService that depends on the abstract OrderRepository makes a requirement that OrderRepository needs to have an effect that can support sequencing via the Monad typeclass constraint (F[_]: Monad) since it needs to sequence actions (i.e. in order to perform an update, it needs to sequence get and put).

There are three interpreters:

  • An in-memory implementation backed by the Id monad
  • A Postgres implementation backed by Slick and Monix Task
  • A DynamoDB implementation backed by Scanamo and scala Futures

Setup instructions for PostgreSQL

Use docker-compose up to bring up a Dockerized PostgreSQL.

Log in to the default postgres database (username = docker, password = docker)

CREATE DATABASE calvin;
GRANT ALL PRIVILEGES ON DATABASE calvin TO docker;

Log into the calvin database (username = docker, password = docker). Make sure you use calvin.<no-schema>

CREATE SCHEMA IF NOT EXISTS example;

The PostgresApp will automatically take care of creating the table in the provided database and schema.

Setup instructions for DynamoDB

Download DynamoDB local. Start it up using:

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

Visit the shell at localhost:8000/shell and create the following table:

const params = {
    TableName: 'orders_by_id',
    KeySchema: [
        {
            AttributeName: 'id',
            KeyType: 'HASH'
        }
    ],
    AttributeDefinitions: [
        {
            AttributeName: 'id',
            AttributeType: 'S' // (S | N | B) for string, number, binary
        }
    ],
    ProvisionedThroughput: {
        ReadCapacityUnits: 10,
        WriteCapacityUnits: 10
    }
};
dynamodb.createTable(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

The DynamoApp will connect to the local database and create records in that table

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].