SlideShare una empresa de Scribd logo
1 de 99
Descargar para leer sin conexión
忘掉 foreach
從此學會 Collection!
LaravelConf Taiwan 2019
自我介紹
工商時間
即時人力服務
達成您交辦的事
享受生活的好幫手
PAOPAOTUI COMPANY
跑跑腿
LINE ID:@85run
Hiring
天瀚國際科技
PHP Senior 後端工程師 60K - 100k * 14
hr@universetech.cc
Environment Version
PHP 7.3.6
Laravel 5.8.28
What is Collection?
Create Collection
1. new
2.
3.
4.
Create Collection
1. new
2. static method
3.
4.
Create Collection
1. new
2. static method
3. helper function
4.
Create Collection
1. new
2. static method
3. helper function
4. wrap
Methods in Collection
Reference https://laravel.com/docs/master/collections#available-methods
Impletement
ArrayAccess
Countable
IteratorAggregate
JsonSerializable
Arrayable
Jsonable
Fluent API
collect()->take(10)->reverse()->toArray()
Before
IlluminateSupportCollecton
vs
IlluminateDatabaseEloquentCollection
When is EloquentCollection
$users = AppUser::all();
$orders = $user->orders
When is SupportCollection
collect();
Builder vs Collection
IlluminateDatabaseConcerns
BuildsQueries
Functional Programming
Pointfree
Divide and Conquer
Pure Function
Immutable
$begin = Carbon::now();
$end = $begin->addHour();
Use FP in Collection
map、filter、reduce
Frequency of use
all()
vs
toArray()
average
avg
contains
each
every
filter
first
flatMap
groupBy
keyBy
map
max
min
partition
reject
some
sortBy
sortByDesc
sum
unique
when
countBy
Higher order messages
Variant
sum()
sum(‘key’)
sum(‘key.id’)
sum(callback)
Extend Collection
Eloquent’s newCollection();
Warning
Type strict
Problem in PHP array
$collection->values()
array_values()
Performance
Not use Laravel?
composer require illuminate/support
composer require tightenco/collect
Reference https://github.com/tightenco/collect
Thanks for your participation

Más contenido relacionado

La actualidad más candente

別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
Yu-Song Syu
 
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
智啓 出川
 
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細(様々なメモリの利用)2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細(様々なメモリの利用)
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
智啓 出川
 

La actualidad más candente (20)

How to use STARC RTL Design Style Guide Verilog-HDL 2011 version
How to use STARC RTL Design Style Guide Verilog-HDL 2011 versionHow to use STARC RTL Design Style Guide Verilog-HDL 2011 version
How to use STARC RTL Design Style Guide Verilog-HDL 2011 version
 
別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
別傻了 你就是不寫測試才會沒時間!CL ft. Hamastar.pdf
 
スクラムによるOpsBear開発2-インセプションデッキ
スクラムによるOpsBear開発2-インセプションデッキスクラムによるOpsBear開発2-インセプションデッキ
スクラムによるOpsBear開発2-インセプションデッキ
 
Linux Namespaces
Linux NamespacesLinux Namespaces
Linux Namespaces
 
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
Javaでやってみる The Twelve Factor App JJUG-CCC 2014 Fall 講演資料
 
PyconJP2017 Kivyによるアプリケーション開発のすすめ
PyconJP2017 Kivyによるアプリケーション開発のすすめPyconJP2017 Kivyによるアプリケーション開発のすすめ
PyconJP2017 Kivyによるアプリケーション開発のすすめ
 
スクレイピングとPython
スクレイピングとPythonスクレイピングとPython
スクレイピングとPython
 
良い?悪い?コードコメントの書き方
良い?悪い?コードコメントの書き方良い?悪い?コードコメントの書き方
良い?悪い?コードコメントの書き方
 
C#, C/CLI と CUDAによる画像処理ことはじめ
C#, C/CLI と CUDAによる画像処理ことはじめC#, C/CLI と CUDAによる画像処理ことはじめ
C#, C/CLI と CUDAによる画像処理ことはじめ
 
オブジェクト指向プログラミング入門 -- Java object-oriented programming primer
オブジェクト指向プログラミング入門 -- Java object-oriented programming primerオブジェクト指向プログラミング入門 -- Java object-oriented programming primer
オブジェクト指向プログラミング入門 -- Java object-oriented programming primer
 
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
2015年度GPGPU実践プログラミング 第10回 行列計算(行列-行列積の高度な最適化)
 
MVC の Model を考える
MVC の Model を考えるMVC の Model を考える
MVC の Model を考える
 
トピックブランチとは
トピックブランチとはトピックブランチとは
トピックブランチとは
 
Djangoによるスマホアプリバックエンドの実装
Djangoによるスマホアプリバックエンドの実装Djangoによるスマホアプリバックエンドの実装
Djangoによるスマホアプリバックエンドの実装
 
CMake multiplatform build-tool
CMake multiplatform build-toolCMake multiplatform build-tool
CMake multiplatform build-tool
 
文脈自由文法の話
文脈自由文法の話文脈自由文法の話
文脈自由文法の話
 
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細(様々なメモリの利用)2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細(様々なメモリの利用)
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
 
FreeNAS 企業應用經驗分享 [2016/12/17] @台中資策會
FreeNAS 企業應用經驗分享 [2016/12/17] @台中資策會FreeNAS 企業應用經驗分享 [2016/12/17] @台中資策會
FreeNAS 企業應用經驗分享 [2016/12/17] @台中資策會
 
ペタッとQR
ペタッとQRペタッとQR
ペタッとQR
 
Beam + Pulsar: Powerful Stream Processing at Scale - Pulsar Summit SF 2022
Beam + Pulsar: Powerful Stream Processing at Scale - Pulsar Summit SF 2022Beam + Pulsar: Powerful Stream Processing at Scale - Pulsar Summit SF 2022
Beam + Pulsar: Powerful Stream Processing at Scale - Pulsar Summit SF 2022
 

Similar a [LaravelConf Taiwan 2019] 忘掉 foreach,從此學會 Collection!

Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
Blake Newman
 
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013
Rack Lin
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
mfrancis
 

Similar a [LaravelConf Taiwan 2019] 忘掉 foreach,從此學會 Collection! (20)

Laravel Restful API and AngularJS
Laravel Restful API and AngularJSLaravel Restful API and AngularJS
Laravel Restful API and AngularJS
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013Phalcon / Zephir Introduction at PHPConfTW2013
Phalcon / Zephir Introduction at PHPConfTW2013
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
2021laravelconftwslides11
2021laravelconftwslides112021laravelconftwslides11
2021laravelconftwslides11
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
 
php
phpphp
php
 
Adventures in Laravel and Performance: Looking beyond eloquent
Adventures in Laravel and Performance: Looking beyond eloquentAdventures in Laravel and Performance: Looking beyond eloquent
Adventures in Laravel and Performance: Looking beyond eloquent
 
DevOps in PHP environment
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
 
Laravel intallation
Laravel intallationLaravel intallation
Laravel intallation
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
Laravel conf taiwan_2018
Laravel conf  taiwan_2018Laravel conf  taiwan_2018
Laravel conf taiwan_2018
 
Java Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIRJava Stammtisch Würzburg - CONAIR
Java Stammtisch Würzburg - CONAIR
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Php through the eyes of a hoster confoo
Php through the eyes of a hoster confooPhp through the eyes of a hoster confoo
Php through the eyes of a hoster confoo
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Eugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk LaravelEugene PHP June 2015 - Let's Talk Laravel
Eugene PHP June 2015 - Let's Talk Laravel
 
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A GrzesikApache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
Apache Karaf - Building OSGi applications on Apache Karaf - T Frank & A Grzesik
 

Más de LaravelConfTaiwan

Más de LaravelConfTaiwan (9)

[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍[LaravelConf Taiwan 2019] 編輯器之華山論劍
[LaravelConf Taiwan 2019] 編輯器之華山論劍
 
[LaravelConf Taiwan 2019] 內部微服務,隊友開發更快速
[LaravelConf Taiwan 2019] 內部微服務,隊友開發更快速[LaravelConf Taiwan 2019] 內部微服務,隊友開發更快速
[LaravelConf Taiwan 2019] 內部微服務,隊友開發更快速
 
[LaravelConf Taiwan 2019] 星移電掣般的 Trace Code!讓你如光速一般的追蹤程式碼
[LaravelConf Taiwan 2019] 星移電掣般的 Trace Code!讓你如光速一般的追蹤程式碼[LaravelConf Taiwan 2019] 星移電掣般的 Trace Code!讓你如光速一般的追蹤程式碼
[LaravelConf Taiwan 2019] 星移電掣般的 Trace Code!讓你如光速一般的追蹤程式碼
 
[LaravelConf Taiwan 2019] 在中國三年,從 0 開始自建完整電商餐飲系統
[LaravelConf Taiwan 2019] 在中國三年,從 0 開始自建完整電商餐飲系統[LaravelConf Taiwan 2019] 在中國三年,從 0 開始自建完整電商餐飲系統
[LaravelConf Taiwan 2019] 在中國三年,從 0 開始自建完整電商餐飲系統
 
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
[LaravelConf Taiwan 2018] 如何正確佈署 Laravel 專案
 
[LaravelConf Taiwan 2018] 針對網路應用程式的資安實踐
[LaravelConf Taiwan 2018] 針對網路應用程式的資安實踐[LaravelConf Taiwan 2018] 針對網路應用程式的資安實踐
[LaravelConf Taiwan 2018] 針對網路應用程式的資安實踐
 
[LaravelConf Taiwan 2018] 訊息通知的奧義 - 大量寄發 Email 及簡訊的技巧
[LaravelConf Taiwan 2018] 訊息通知的奧義 - 大量寄發 Email 及簡訊的技巧[LaravelConf Taiwan 2018] 訊息通知的奧義 - 大量寄發 Email 及簡訊的技巧
[LaravelConf Taiwan 2018] 訊息通知的奧義 - 大量寄發 Email 及簡訊的技巧
 
[LaravelConf Taiwan 2018] 跨境電商的眉眉角角
[LaravelConf Taiwan 2018] 跨境電商的眉眉角角[LaravelConf Taiwan 2018] 跨境電商的眉眉角角
[LaravelConf Taiwan 2018] 跨境電商的眉眉角角
 
[LaravelConf Taiwan 2018] 工程師的大航道之路
[LaravelConf Taiwan 2018] 工程師的大航道之路[LaravelConf Taiwan 2018] 工程師的大航道之路
[LaravelConf Taiwan 2018] 工程師的大航道之路
 

Último

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Último (20)

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 

[LaravelConf Taiwan 2019] 忘掉 foreach,從此學會 Collection!