Created
May 27, 2021 19:15
-
-
Save arnaudgeiser/0ac34c82d63b2e8ffa8aa148a551b6e6 to your computer and use it in GitHub Desktop.
Transformation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Unversité valide! | |
(def universite | |
{:nom "UniFR" | |
:etudiants [{:nom "Geiser" | |
:prenom "Arnaud" | |
:admissions [{:semestre "SP-2020" :statut "Immatricule"} | |
{:semestre "SA-2020" :statut "Immatricule"} | |
{:semestre "SP-2021" :statut "Immatricule"} | |
{:semestre "SA-2021" :statut "Immatricule"}]} | |
{:nom "Rosset" | |
:prenom "Matthieu" | |
:admissions [{:semestre "SP-2021" :statut "Immatricule"} | |
{:semestre "SA-2021" :statut "Admis"}]}]}) | |
;; Admission immatriculé pour un semestre | |
(defn admission-immatricule-semestre [etudiant semestre] | |
(let [admissions (:admissions etudiant)] | |
(->> admissions | |
(filter #(= "Immatricule" (:statut %))) | |
(filter #(= semestre (:semestre %))) | |
(first)))) | |
;; Etudiants immatriculés | |
(defn etudiants-immatricules [uni semestre] | |
(let [etudiants (:etudiants uni)] | |
(for [etudiant etudiants | |
:let [admission (admission-immatricule-semestre etudiant semestre)] | |
:when admission] | |
(merge (select-keys etudiant [:nom :prenom]) admission)))) | |
(prn (etudiants-immatricules universite "SP-2020")) ;; ({:nom "Geiser", :prenom "Arnaud", :semestre "SP-2020", :statut "Immatricule"}) | |
(prn (etudiants-immatricules universite "SP-2021")) ;; ({:nom "Geiser", :prenom "Arnaud", :semestre "SP-2021", :statut "Immatricule"} {:nom "Rosset", :prenom "Matthieu", :semestre "SP-2021", :statut "Immatricule"}) | |
(prn (etudiants-immatricules universite "SA-2021")) ;; ({:nom "Geiser", :prenom "Arnaud", :semestre "SA-2021", :statut "Immatricule"}) | |
;; Avec null, ça marche aussi! | |
(prn (etudiants-immatricules nil "SA-2021")) => () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment