5

I have this collection of movies by directors:

([{:title "Blade Runner 2049", :genre "Action", :year 2017} {:title "Gladiator", :genre "Drama", :year 2000} {:title "Mars", :genre "Adventure", :year 2015} {:title "American Gangster", :genre "Crime", :year 2007}] [{:title "The Godfather", :genre "Crime", :year 1972} {:title "Apocalypse Now", :genre "Drama", :year 1979} {:title "Jack", :genre "Comedy", :year 1996}] [{:title "The Wolf", :genre "Comedy", :year 2013} {:title "GoodFellas", :genre "Crime", :year 1990} {:title "The Departed", :genre "Drama", :year 2006} {:title "The Aviator", :genre "Drama", :year 2004}]) 

which is a list of 3 vectors(Directors) and the corresponding movies

If I do:

(doseq [directors-movie movies] (doseq [movie directors-movie] (println movie))) 

I can print all movies one by one:

#imdb.movie.Movie{:title Blade Runner 2049, :genre Action, :year 2017} #imdb.movie.Movie{:title Gladiator, :genre Drama, :year 2000} #imdb.movie.Movie{:title Mars, :genre Adventure, :year 2015} #imdb.movie.Movie{:title American Gangster, :genre Crime, :year 2007} #imdb.movie.Movie{:title The Godfather, :genre Crime, :year 1972} #imdb.movie.Movie{:title Apocalypse Now, :genre Drama, :year 1979} #imdb.movie.Movie{:title Jack, :genre Comedy, :year 1996} #imdb.movie.Movie{:title The Wolf, :genre Comedy, :year 2013} #imdb.movie.Movie{:title GoodFellas, :genre Crime, :year 1990} #imdb.movie.Movie{:title The Departed, :genre Drama, :year 2006} #imdb.movie.Movie{:title The Aviator, :genre Drama, :year 2004} 

What I need is to put all this movies into a Vector.

Thanks, R.

2 Answers 2

10
(reduce into [] l) 

or

(into [] cat l) 

will do (where l is your input list)

Sign up to request clarification or add additional context in comments.

2 Comments

(apply concat data) has less tokens )
(into [] cat l) has less tokens than (apply concat data) and produces a vector, like was asked for :-)
3

This will do it:

(-> movies flatten vec) 

Alternatives are:

(->> movies (apply concat) vec) 

, and:

(->> movies (mapcat identity) vec) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.