dev-resources.site
for different kinds of informations.
Clojure Is Awesome!!! [PART 4]
Published at
12/23/2024
Categories
clojure
designpatterns
cleancode
clj
Author
borba
Author
5 person written this
borba
open
(ns monostate)
(def ^:private session-state
(atom {:user-id nil
:permissions #{}
:last-access nil}))
(defn start-session
"Starts a new user session with ID and permissions."
[user-id permissions]
(reset! session-state {:user-id user-id
:permissions permissions
:last-access (java.time.Instant/now)}))
(defn end-session
"Ends the session, resetting the state to default values."
[]
(reset! session-state {:user-id nil
:permissions #{}
:last-access nil}))
(defn update-last-access
"Updates the last access timestamp to the current time."
[]
(swap! session-state assoc :last-access (java.time.Instant/now)))
(defn get-session
"Retrieves the complete state of the current session."
[]
@session-state)
(defn has-permission?
"Checks if the user has a specific permission."
[permission]
(contains? (:permissions @session-state) permission))
(comment
(start-session "user-123" #{"read" "write"})
;; => {:user-id "user-123", :permissions #{"read" "write"}, :last-access <timestamp>}
(has-permission? "read") ;; => true
(has-permission? "delete") ;; => false
(update-last-access)
(get-session)
;; => {:user-id "user-123", :permissions #{"read" "write"}, :last-access <new-timestamp>}
(end-session)
;; => {:user-id nil, :permissions #{}, :last-access nil}
)
clojure Article's
30 articles in total
25 Must-Check Clojure Resources for Developers: Tutorials, Tools, and Tips
read article
Is it easy to manage a team of highly qualified engineers?
read article
[PT-BR] Functional vs OOP: Uma análise profunda dos paradigmas de programação
read article
From Chaos to Control
read article
The capacity to learn new languages is very important
read article
Transducer: A powerful function composition pattern
read article
Clojure Is Awesome!!! [PART 4]
currently reading
Episode 3: Once you try Clojure, there is no way back
read article
Clojure Is Awesome!!! [PART 3]
read article
Clojure Is Awesome!!! [PART 2]
read article
Clojure in Product podcast
read article
Early termination of transducers and reducing functions
read article
Clojure is Awesome!!!
read article
To transduce or not to transduce?
read article
Clojure in Product podcast, 2nd episode
read article
Clojure REPL-Driven Development with VS Code
read article
10 Soft Skills que Aprendi Durante 3 Anos Criando Soluções para 100 Milhões de Usuários
read article
Scheming About Clojure
read article
Calling Clojure from Java using a real example (Clojure + Quarkus)
read article
Querido Yo del Futuro: Hoy intentaremos configurar una aplicación fullstack en Clojure
read article
Never call the same function twice (with memoization)
read article
The Clojure Paradox
read article
Why I chose Clojure/Script for building Vade Studio
read article
How I’m learning Clojure in 2024
read article
Krestianstvo Electric Lazy Reflector for Croquet VM
read article
Implementing a 2d-tree in Clojure
read article
Need microservice? Take Clojure!
read article
Transducers and Eduction in Clojure simply explained
read article
Meet Datomic: the immutable and functional database.
read article
Java Allergies and Revisiting java.time
read article
Featured ones: