添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
温柔的香烟  ·  java如何命令行输入 n ...·  3 周前    · 
飘逸的感冒药  ·  POCOViewModel and ...·  5 月前    · 
苦闷的墨镜  ·  Spring - non null key ...·  5 月前    · 
不爱学习的甘蔗  ·  USAJOBS - Search·  8 月前    · 
$collection = collect([1, 2, 3, 4, 5]);
$filtered = $collection->reject(function ($item) {
    return $item % 2 == 0; // Exclude even numbers
dd($filtered->all()); // Output: [1, 3, 5]
    Enter fullscreen mode
    Exit fullscreen mode
$collection = collect([1, 2, 3, 4, 5]);
$squared = $collection->map(function ($item) {
    return $item * $item; // Square each number
dd($squared->all()); // Output: [1, 4, 9, 16, 25]
    Enter fullscreen mode
    Exit fullscreen mode

In summary, while reject is your tool for excluding items, map is your friend for transforming them. Choose the right function based on your data manipulation needs.

Happy coding! 🚀

Built on Forem — the open source software that powers DEV and other inclusive communities.

Made with love and Ruby on Rails. DEV Community © 2016 - 2024.