DEV Community

Cover image for Clojure Is Awesome!!! [PART 3]
André Borba
André Borba

Posted on

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

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay