All Projects → scalalandio → Chimney

scalalandio / Chimney

Licence: apache-2.0
Scala library for boilerplate-free, type-safe data transformations

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Chimney

Vortigern
A universal boilerplate for building web applications w/ TypeScript, React, Redux, Server Side Rendering and more.
Stars: ✭ 647 (-11.49%)
Mutual labels:  boilerplate
Boilerform
Boilerform is a little HTML and CSS boilerplate to take the pain away from working with forms.
Stars: ✭ 679 (-7.11%)
Mutual labels:  boilerplate
Nextjs Mongodb App
A Next.js and MongoDB web application, designed with simplicity for learning and real-world applicability in mind.
Stars: ✭ 694 (-5.06%)
Mutual labels:  boilerplate
Base
A starting point for Meteor apps.
Stars: ✭ 654 (-10.53%)
Mutual labels:  boilerplate
Python Project Blueprint
Blueprint/Boilerplate For Python Projects
Stars: ✭ 670 (-8.34%)
Mutual labels:  boilerplate
Django React Template
Django & React Template For Building Web Applications
Stars: ✭ 686 (-6.16%)
Mutual labels:  boilerplate
React Native Meteor Boilerplate
Stars: ✭ 637 (-12.86%)
Mutual labels:  boilerplate
React Clean Architecture
A realistic approach to implement clean architecture on react codebases
Stars: ✭ 713 (-2.46%)
Mutual labels:  boilerplate
Rest Api Nodejs Mongodb
A boilerplate for REST API Development with Node.js, Express, and MongoDB
Stars: ✭ 672 (-8.07%)
Mutual labels:  boilerplate
React Native Web Monorepo
Code sharing between iOS, Android & Web using monorepo
Stars: ✭ 697 (-4.65%)
Mutual labels:  boilerplate
Postgrest Starter Kit
Starter Kit and tooling for authoring REST API backends with PostgREST
Stars: ✭ 657 (-10.12%)
Mutual labels:  boilerplate
React Starterify
A minimal React JS application starter kit
Stars: ✭ 669 (-8.48%)
Mutual labels:  boilerplate
Bozon
🛠 Command line tool for building, testing and publishing modern Electron applications
Stars: ✭ 687 (-6.02%)
Mutual labels:  boilerplate
React Isomorphic Boilerplate
🌟 An universal React isomorphic boilerplate for building server-side render web app.
Stars: ✭ 653 (-10.67%)
Mutual labels:  boilerplate
Akka Http Microservice
Example of http (micro)service in Scala & akka-http
Stars: ✭ 701 (-4.1%)
Mutual labels:  boilerplate
React Redux Universal Hot Example
A starter boilerplate for a universal webapp using react, redux, express and feathers
Stars: ✭ 639 (-12.59%)
Mutual labels:  boilerplate
Aws Boilerplate
Opinionated full stack web app's boilerplate, ready to be deployed to AWS platform.
Stars: ✭ 682 (-6.7%)
Mutual labels:  boilerplate
Jslib Base
A modern JavaScript|Typescript library scaffolding, modularity, purity & extras
Stars: ✭ 721 (-1.37%)
Mutual labels:  boilerplate
Laravel Boilerplate
Laravel Boilerplate / Starter Kit with Gentelella Admin Theme
Stars: ✭ 704 (-3.69%)
Mutual labels:  boilerplate
Rebar
Multi-tenant SaaS boilerplate + examples for universal web application with React, Material-UI, Relay, GraphQL, JWT, Node.js, C* DB - Cassandra/Elassandra/Scylla.
Stars: ✭ 690 (-5.61%)
Mutual labels:  boilerplate

Chimney Chimney logo

CI build Maven Central Javadocs codecov.io License Join the chat at https://gitter.im/scalalandio/chimney Scala.js

Scala library for boilerplate-free data transformations.

In the daily life of a strongly-typed language's programmer sometimes it happens we need to transform an object of one type to another object which contains a number of the same or similar fields in their definitions.

case class MakeCoffee(id: Int, kind: String, addict: String)
case class CoffeeMade(id: Int, kind: String, forAddict: String, at: ZonedDateTime)

Usual approach is to just rewrite fields one by one

val command = MakeCoffee(id = Random.nextInt,
                         kind = "Espresso",
                         addict = "Piotr")
val event = CoffeeMade(id = command.id,
                       kind = command.kind,
                       forAddict = command.addict,
                       at = ZonedDateTime.now)

While the example stays lean, in real-life code we usually end up with tons of such boilerplate, especially when:

  • we maintain typed schema and want to migrate between multiple schema versions
  • we apply practices like DDD (Domain-Driven-Design) where suggested approach is to separate model schemas of different bounded contexts
  • we use code-generation tools like Protocol Buffers that generate primitive types like Int or String, while you'd prefer to use value objects in you domain-level code to improve type-safety and readability

Chimney provides a compact DSL with which you can define transformation rules and transform your objects with as little boilerplate as possible.

import io.scalaland.chimney.dsl._

val event = command.into[CoffeeMade]
  .withFieldComputed(_.at, _ => ZonedDateTime.now)
  .withFieldRenamed(_.addict, _.forAddict)
  .transform

Underneath it uses Scala macros to give you:

  • type-safety at compile-time
  • fast generated code, almost equivalent to hand-written version
  • excellent error messages
  • minimal overhead on compilation time

Getting started

To include Chimney to your SBT project, add the following line to your build.sbt:

libraryDependencies += "io.scalaland" %% "chimney" % "0.6.1"

Library is released for Scala 2.12.x and 2.13.x.

If you want to use it with Scala.js, you need to replace %% with %%%. Due to some compiler bugs, it's recommended to use at least Scala 2.12.1.

Trying with Ammonite REPL

The quickest way to try out Chimney is to use a script that downloads coursier and uses it to fetch Ammonite REPL with the latest version of Chimney. It drops you immediately into a REPL session.

curl -s https://raw.githubusercontent.com/scalalandio/chimney/master/try-chimney.sh | bash
Loading...
Welcome to the Ammonite Repl 1.1.0
(Scala 2.12.4 Java 1.8.0_152)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ case class Foo(x: String, y: Int) 
defined class Foo

@ case class Bar(x: String, y: Int, z: Boolean = true) 
defined class Bar

@ Foo("abc", 10).transformInto[Bar] 
res2: Bar = Bar("abc", 10, true)

Documentation

Chimney documentation is available at https://scalalandio.github.io/chimney

Building documentation locally

In order to build documentation locally, you need to install Sphinx documentation generator first.

Then in project's root directory run command:

sbt makeSite

HTML Documentation should be generated at target/sphinx/html/index.html.

Thanks

Thanks to JProfiler (Java profiler) for helping us develop the library and allowing us to use it during development.

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].