Scala 3 Data Transformation Library: Automating Data Transformations with ducktape

In the ever-evolving landscape of software development, there are tasks that, while necessary, often lack the thrill of innovation. One such task involves managing data transformations, a critical aspect across various domains. While JSON APIs serve as a prime example where such transformations are crucial, the focus of this discussion transcends JSON and centers on ducktape – a Scala 3 data transformation micro-library designed to revolutionize how developers approach automatic and configurable data transformations. This article takes you through the journey of ducktape, showcasing its power to simplify data model conversions and enhance the efficiency of development workflows.

The Challenge of Data Transformations

In software development, working with data transformations is an everyday necessity. Regardless of the data format or application domain, mapping and converting data structures can be laborious and error-prone. Developers typically need help with the complexities of model conversions between different (often pretty similar to each other) data models, diverting their attention from core business logic and innovation.

Unveiling ducktape: A Paradigm Shift

Not to be confused with its adhesive counterpart, ducktape emerges as a game-changing solution to the intricate web of data transformations. At its core, the libaempowers scala developers to convert data models between different formats seamlessly. This transformation-centric micro library introduces a novel approach to simpler domain modeling, prioritizing automatic data conversion over manual coding. The essence of ducktape lies in its ability to shift the focus away from mundane data-handling tasks, allowing scala developers to dedicate more energy to innovative endeavors.

Key Principles of ducktape

Central Role of Transformers

Transformers lie at the heart of ducktape’s philosophy. These components serve as the bridge between data structures, enabling fluid transitions from one format to another. Within ducktape’s context, a transformer guarantees successful transformations during runtime, possibly encountering compile-time failures if necessary transformations are unavailable. These transformers, designed as type classes, facilitate intricate transformation chains for complex scenarios.

Exclusive Scala 3 Compatibility

Ducktape’s niche lies within the Scala 3 programming language. This exclusivity opens doors to advanced macro features inherent in Scala 3, elevating the library’s implementation. Leveraging Scala 3’s robust type system and macro capabilities, ducktape achieves unparalleled transformation seamlessness (or a little bit paralleled by chimney, which just had its first Scala 3 release).

Automated Derivation: The Jewel in the Crown

A standout feature of ducktape is its prowess in automating the derivation of transformers for case classes and enums. This automated magic unfolds by scrutinizing source and target case class composition and types, generating the requisite transformation logic.

Reimagining Data Transformation Workflows

Ducktape orchestrates a transformational shift in the conventional data workflow, simplifying its multistep journey:

  1. Defining Data Models: ducktape encourages developers to define data models using case classes and enums. These models represent the core structures of both the domain and the API while not shying away from representing different layers of their apps with models made specifically for that particular layer.
  2. Automated Derivation: ducktape takes the reins of transformer derivation, sparing scala developers from manually crafting transformation logic.
  3. Customizable Transformations: Developers enjoy the flexibility of tailoring transformations through various configuration options. These include constants, computed values, field renaming, and multiple others.
  4. Validation and Error Handling: ducktape assumes responsibility for validation and error reporting during transformations. It aggregates errors, presenting developers with a comprehensive overview of areas needing attention.
  5. Integration of Business Logic: Developers can implement business logic once data models are in place and transformers are derived. The streamlined API development facilitated by ducktape paves the way for more effective functionality realization.

A Practical Glimpse: Transforming Conference Data

To exemplify ducktape’s prowess, let’s traverse a real-world scenario. Imagine constructing a REST API for conference management. Employing case classes, ducktape automates the conversion between domain and API representations:

case class CreateConference(name: ConfName, dateSpan: DateSpan, city: CityName)

case class Conference(name: ConfName, dateSpan: DateSpan, city: CityName)

Note how custom new types, constructed using Scala 3’s opaque type feature, bolster validation and guarantee accuracy.

Empowering Development with ducktape

Ducktape radically simplifies the transformation endeavor. By harnessing automated derivation, the Scala 3 data transformation library conjures transformation logic on our behalf. Consider the example above – transforming `CreateConference` instances into `Conference` instances is now an effortless feat:

val createConf: CreateConference = ... // API request body

val conf: Conference =[Conference]

Behind the scenes, ducktape orchestrates field mapping and executes vital validations. While automatic derivation champions most scenarios, intricate use cases may necessitate additional configurations. Here, ducktape’s `into` and `via` methods come into play, elegantly handling such complexities.

Advantages and Cautions


  • Enhanced Efficiency: Ducktape eliminates the tedium of transformation tasks, optimizing resource allocation.
  • Streamlined Simplicity: Automatic derivation negates the need for extensive boilerplate code, fostering cleaner, more maintainable codebases.
  • Customization Capabilities: Ducktape’s configurability empowers scala developers to tackle unique cases unaddressed by automatic derivation.

Points of Note

  • Learning Curve: While ducktape simplifies many dimensions of API development, a grasp of its principles and mechanics is imperative.
  • Handling Edge Cases: While automated derivation caters to most scenarios, intricate transformations or edge cases might necessitate manual intervention.

So, where can you learn more? 

First, check out the video recording of the creator of Ducktape, Aleksander Rainko, from the SF Scala meetup. This video will give you valuable insights and details about the library’s capabilities.

But that’s not all! Head over to Ducktape’s GitHub page to explore the library’s documentation and get started with quicker data transformations.

ducktape Scala 3 data transformation library

Don’t let data transformations slow you down. Let ducktape support you in automating your data conversions and making your development process more manageable.

Scala 3 data transformation library

Scala 3 data transformation library | In Closing

Ducktape emerges as an indispensable asset for developers yearning to automate and streamline data transformation complexities. By zeroing in on automatic and customizable transformations, the Scala 3 data transformation library unburdens scala developers from menial tasks, allowing them to channel their energy into innovative problem-solving and application enhancement. With its integration into Scala 3 and harnessing of robust macro features, ducktape introduces a modern approach to API development, revolutionizing the developer’s engagement with data models, irrespective of their format.

Don’t forget to watch the video, visit the GitHub page, and unlock the power of ducktape with Scalac expertise today!


Daria Karasek
Daria Karasek

Marketing Hero at Scalac. I strongly believe in creating opportunities rather than waiting for them to come. As befits Scalac team member I'm a hard worker, I always try to do the right thing and have a lot of fun! I'm an awesome friend and content writer, in that order. When I'm out of the office, I love to cook delicious Italian food and play board games with my friends. #boardgamegeek

Latest Blogposts

05.12.2023 / By  Michał Talaśka , Michał Talaśka

Advantage of Team-Extension: success through speed, cost-efficiency and quality.

Traditional hiring vs team-extension In the fiercely competitive arena of IT, companies grapple with strategies that will drive them ahead of the curve. The goal is straightforward yet immensely challenging: achieving operational excellence and innovation prowess. Herein, a pivotal factor emerges—the acquisition of top-tier talent proficient in driving tech objectives forward with expert skills. Choosing […]

30.11.2023 / By  Matylda Kamińska

Scalendar December 2023

Event-driven Newsletter As we bid farewell to another year filled with technological evolution and groundbreaking innovations, we are happy to present the December edition of our monthly roundup, featuring key events from the realms of Scala, Software Architecture, Frontend, and Go. In this compilation, we capture the month, highlighting noteworthy conferences, meetups, and developments that […]

24.11.2023 / By  Sylwia Wysocka

Navigating the Future at Web Summit 2023: A First-Timer’s Reflection

Insights and Reflections: My First Web Summit Experience Join me, a business development specialist from Scalac, on my first-ever journey through the buzzing halls of Web Summit 2023 in Lisbon. As I stepped into this ocean of innovation and opportunity, I was filled with a mix of excitement and curiosity. What unfolded over the next […]

Need a successful project?

Estimate project