Skip to content

Commit 5e2cf45

Browse files
committedMay 21, 2022
Yaml file practice
1 parent 3d9d4eb commit 5e2cf45

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed
 

‎project.clj

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
:dependencies [
77
[org.clojure/clojure "1.10.3"]
88
[prismatic/schema "1.2.0"]
9+
[io.forward/yaml "1.0.11"]
910
]
1011
:main ^:skip-aot clojure-noob.core
1112
:target-path "target/%s"

‎resources/yaml-example.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: "Karina"
2+
surname: "Moreira"
3+
profileDetails:
4+
- birthday: "18/05"
5+
- numberOfPets: 1
6+
- hobbies: ["manga", "series", "games"]

‎src/clojure_noob/ch04/exercises.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ transformed-list
257257

258258
; max expects different arguments, but a vector
259259
; is a single argument
260-
(max [0 1 2]) ; => [0 1 2]
260+
;(max [0 1 2]) ; => [0 1 2]
261261

262262
; apply explodes a seqable data structure
263263
; like this vector, passing its values as arguments
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(ns clojure-noob.side-studies.studies.yaml-stuff
2+
(:require
3+
[yaml.core :as yaml]
4+
[clojure.java.io :as io]))
5+
6+
; same effect
7+
(-> (io/file ".") .getAbsolutePath)
8+
(-> (java.io.File. ".") .getAbsolutePath)
9+
10+
(def yaml-filepath
11+
"resources/yaml-example.yml")
12+
13+
(slurp yaml-filepath)
14+
(.exists (io/file yaml-filepath))
15+
(.exists (io/resource yaml-filepath))
16+
17+
(yaml/from-file (io/file yaml-filepath))
18+
(:surname (yaml/from-file (io/file yaml-filepath)))
19+
(yaml/generate-string (yaml/from-file (io/file yaml-filepath)))

0 commit comments

Comments
 (0)