Logo

dev-resources.site

for different kinds of informations.

Clojure Is Awesome!!! [PART 3]

Published at
12/17/2024
Categories
clojure
designpatterns
clj
cleancode
Author
borba
Author
5 person written this
borba
open
Clojure Is Awesome!!! [PART 3]
(ns builder)

(defn create-report
  "Creates an initial structure for the report."
  []
  {:title    nil
   :author   nil
   :date     nil
   :content  []
   :summary  nil})

(defn set-title
  "Sets the title of the report."
  [report title]
  (assoc report :title title))

(defn set-author
  "Sets the author of the report."
  [report author]
  (assoc report :author author))

(defn set-date
  "Sets the date of the report."
  [report date]
  (assoc report :date date))

(defn add-content
  "Adds a section to the report content."
  [report section]
  (update report :content conj section))

(defn set-summary
  "Adds a summary to the report."
  [report summary]
  (assoc report :summary summary))

(defn build-report
  "Validates and returns the finalized report."
  [report]
  (if (and (:title report) (:author report) (:content report))
    report
    (throw (IllegalArgumentException. "Invalid report: title, author, and content are mandatory."))))

(defn generate-sample-report []
  (-> (create-report)
      (set-title "Annual Financial Report")
      (set-author "Finance Department")
      (set-date "2024-12-13")
      (add-content "Introduction to financial results.")
      (add-content "Analysis of expenses and revenues.")
      (set-summary "This report provides a detailed overview of the annual financial performance.")
      (build-report)))

(comment
  (generate-sample-report)
  ;; => {:title "Annual Financial Report", 
  ;;     :author "Finance Department", 
  ;;     :date "2024-12-13", 
  ;;     :content ["Introduction to financial results." "Analysis of expenses and revenues."], 
  ;;     :summary "This report provides a detailed overview of the annual financial performance."}
)
Enter fullscreen mode Exit fullscreen mode
cleancode Article's
30 articles in total
Favicon
STOP Writing Dirty Code: Fix The Data Class Code Smell Now!
Favicon
Абстракции vs. привязка к технологии
Favicon
An Initiation to Domain-Driven Design
Favicon
7 Essential Design Patterns for JavaScript Developers: Boost Your Coding Mastery
Favicon
Orden en el Código .NET
Favicon
Movie X: A Developer’s Dive Into Flutter Project Organization
Favicon
3 Code Comment Mistakes You're Making Right Now
Favicon
From Chaos to Control
Favicon
Clean code
Favicon
Want to Learn Docker in Advance Way?
Favicon
3 very simple React patterns to immediately improve your codebase 🪄
Favicon
Refactoring 021 - Remove Dead Code
Favicon
Code Commenting Ethics: When Over-Documentation Hurts Development
Favicon
Clean Code: Managing Side Effects with Functional Programming
Favicon
Why Use Getters and Setters?!
Favicon
Clojure Is Awesome!!! [PART 4]
Favicon
Clojure Is Awesome!!! [PART 3]
Favicon
Python's Magic Methods
Favicon
Clojure Is Awesome!!! [PART 2]
Favicon
Why should I care about Quality? I'm a developer!
Favicon
Mastering Laravel Blade: @stack, @push, and @endpush
Favicon
How to write a good Clean code? - Tips for Developers with Examples
Favicon
Union and Intersection Types in TypeScript
Favicon
Arquitetura Viva: Moldando Sistemas para Mudanças
Favicon
Dependency Injection in ASP.NET Core with Extension Classes: A Comprehensive Guide
Favicon
Rails transactional callbacks beyond models
Favicon
Python Best Practices: Writing Clean and Maintainable Code
Favicon
Excited to Be Part of This Community! 🚀
Favicon
Single Responsibility Principle in Javascript
Favicon
Build Express APIs Faster than AI

Featured ones: