Git Product home page Git Product logo

domain-modelling-made-functional's Introduction

What is it?

A Scala version of https://github.com/swlaschin/DomainModelingMadeFunctional Some more flavors will come. Plan is to use idiomatic Scala version as opposed to F# in Scala. Next thing to come is to use ZLayer instead of curried functions DI.

JSON won't be implemented.

Type annotations

Scala requires more of them than F#. It has pros and cons. I, as a programmer, had problem with inferring type OrderQuantity.create productCode parameter and is other places. Parameter name is usually enough for me. Another value I see in type ascriptions is that F# requires more comments.

'let' vs 'val' and 'def'

Another difference is that F# uses let and that's it. In Scala I need two things: val and def. The second one usually when I need type params.

curried syntax

I use it in most places here, I don't like it. Scala is not Haskell nor F#. Which one looks better for non-programmer? I don't know. I don't know any non-programmer :-)

'Result'

I added Result like in F# original version, however I kept error on left side. I didn't add AsyncResult - too much hassle. I'm using IO from ZIO. Somehow I couldn't make type aliases to be visible everywhere (however I didn't try hard), that's a pity.

Dotty

At some point I'll try to rewrite with opaque types and sum types... Philip Schwarz got it covered!

https://www.slideshare.net/pjschwarz/scala-3-by-example-algebraic-data-types-for-domain-driven-design-part-1

Files

I kept files almost like in F# original. Awkward in Scala I think. I merged SimpleTypes and CompoundTypes in package object.

End result

I don't think it's a code that domain expert would event try to comprehend. However for me it's much better than what I usually produce.

Idiomatic Scala

It's subjective but I like it more than naive translation. I removed many types definitions and I use them inline. It's easier to me to read exact type than trying to remember if this dependency was A => B or WrappedA => Result[Err, B] or A => IO[Err, B]. What is nice about F# is that it requires so few constructs: one let vs def and val for example. I don't like curried application with parentheses in Scala. I prefer parameters lists.

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.