3 ms·
That's a question of code organization, one method I find helpful is writing a long chain and then breaking it up into clear functions. E.g. var longBooks
by solid_fuel 2y ago
That's a question of code organization, one method I find helpful is writing a long chain and then breaking it up into clear functions. E.g.
var longBooks = books.filter(book => book.pageCount > 1000)
var authors = longBooks.map(book => book.author)
var distinctAuthors = authors.distinct()
could become (in a different language)
books
|> Books.filter_by_length(min: 1000)
|> Authors.from_books()
|> Enum.distinct()
and now each step is named and reusable. This example isn't the best, but it can be quite helpful when you have large map() and filter() logic blocks.