Search code examples
clojure

How to Output a Set as Simple Strings?


I need to give an output like this:

/Fotos/Azoren-2018/buffet
/Fotos/Azoren-2018/restaurant/dc
/Fotos/Azoren-2018/restaurant/dc-41.jpg
/Fotos/Azoren-2018/restaurant/dc-42.jpg
/Fotos/Azoren-2018/restaurant/dc-43.jpg
/Fotos/Mallorca-2017/dc-10.jpg
/Fotos/Mallorca-2017/dc-11.jpg
/Fotos/Mallorca-2017/dc-19.jpg

But I think my output is a set:

#{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}

Any ideas how can I convert that set into this output?


Solution

  • Use sort with clojure.string/join:

    (->> #{"/Fotos/Mallorca-2017/dc-10.jpg" "/Fotos/Azoren-2018/buffet" "/Fotos/Azoren-2018/restaurant/dc-43.jpg" "/Fotos/Azoren-2018/restaurant/dc-42.jpg" "/Fotos/Mallorca-2017/dc-19.jpg" "/Fotos/Azoren-2018/restaurant/dc-41.jpg" "/Fotos/Mallorca-2017/dc-11.jpg" "/Fotos/Azoren-2018/restaurant/dc"}
         sort
         (clojure.string/join "\n")
         println)
    

    Output:

    /Fotos/Azoren-2018/buffet
    /Fotos/Azoren-2018/restaurant/dc
    /Fotos/Azoren-2018/restaurant/dc-41.jpg
    /Fotos/Azoren-2018/restaurant/dc-42.jpg
    /Fotos/Azoren-2018/restaurant/dc-43.jpg
    /Fotos/Mallorca-2017/dc-10.jpg
    /Fotos/Mallorca-2017/dc-11.jpg
    /Fotos/Mallorca-2017/dc-19.jpg
    => nil