Prism · Sugar
$flatMap
Maps each element to a list and joins those lists into one. Shorthand for a $flatten over a $map.
{
folders: [
{ name: 'work', files: ['report.pdf', 'notes.md'] },
{ name: 'personal', files: ['photo.jpg'] },
{
name: 'archive',
files: ['old.txt', 'older.txt', 'oldest.txt'],
},
],
}{
$flatMap: {
over: { $ref: '$.folders' },
as: 'folder',
body: { $get: { from: { $var: 'folder' }, path: ['files'] } },
},
}[ 'report.pdf', 'notes.md', 'photo.jpg', 'old.txt', 'older.txt', 'oldest.txt', ]
Runs in this page on the installed package. The input and the expected output are defined by the example.