SlideShare una empresa de Scribd logo
1 de 12
Implicit classes
Almost as beautiful as Trump’s hair
Extensions are amazing!
Why?
result match {
case Success(_) =>
case Failure(ex) =>
Logger.error(s"Failed to comment project ${project.id}”)
}
I HATE BOILERPLATE
result.logException(s"Failed to comment project ${project.id}”)
And even logs the exception,
that sometimes we love to
hide...
Implementation
implicit class TryExtension[T](nativeTry: Try[T]) {
private val defaultMsg: String = "Try is a failure"
def logException(logger: String => Unit = defaultLogger, msg: String = defaultMsg): Try[T] = {
nativeTry match {
case Success(_) =>
nativeTry
case Failure(e) =>
val msgWithStacktrace =
s"""
|$msg
|message: ${e.getMessage}
|${e.getStackTrace.mkString(System.lineSeparator)}
""".stripMargin
logger(msgWithStacktrace)
nativeTry
}
}
private def defaultLogger(msgWithStacktrace: String): Unit = Logger.error(msgWithStacktrace)
}
Although it uses “implicit”, remember that
you still have to call the methods explicitly!
So the “hate on implicits” arguments don’t
apply ;)
It’s not about knowing how to do it, it is
about doing it! Instead of copypasta more
bolierplate..
.orElse {
Logger.error(s"Failed to updated Heroku user: RequestURL=$url Response=${response.json}")
None
}
Pretty much as we did a .logException(), we can easily do a
.logNone()!
.logNone(s"Failed to updated Heroku user: RequestURL=$url Response=${response.json}")
It can be more than
just logs
Although I like to use the extensions
on logs, (because we don’t care about
them, we just want the bad guys to be
logged, and it always the same thing)
there are MANY MORE cases where
we can use them.
if (!updated) {
ProjectRules.addUserToProject(
projectId,
teamMember.userIdentifier,
teamMember.permission
)
}
updated
Boolean Extension :D
updated.onFalse {
ProjectRules.addUserToProject(
projectId,
teamMember.userIdentifier,
teamMember.permission
)
}
updated //not needed
.onFalse() returns the boolean itself, so no need to repeat
the “updated”
Plenty of great use cases!
//potatos: Seq[A]
potatos.distinctBy(_.weight) //Instead of CollectionHelper.distinctBy(potatos, _.weight)
//res: Option[A]
res.toResponse(msg = “Failed xxx”)
//res: Try[A]
res.toResponse()
…….
Implicit Classes Everywhere???
The “Extension” types are just a way to achieve
extension methods. Never use their types!
For example “TryExtension” should only be mentioned
on the import itself, shouldn’t be use anywhere else! We
just want the methods, not the type of the class
And also, PLEASE don’t do implicit extensions on
classes that we own!
If if is our code, we can just go there and add a method!
“Don’t wanna update foundation” is not an excuse to
start making implicit classes that extend our Response!
“he who yields the chalice shall have
everlasting awesomeness”
- The ancient council of elders
Thank you!
João Machado
machado@codacy.com
https://github.com/machadoit
Meet our team at:
https://www.codacy.com
Review less, merge faster
Check code style, security, duplication, complexity and coverage on every
change while tracking code quality throughout your sprints.

Más contenido relacionado

La actualidad más candente

Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Julien Vinber
 
Macro Copy Paste Special Value Vba
Macro   Copy Paste Special Value   VbaMacro   Copy Paste Special Value   Vba
Macro Copy Paste Special Value Vbarobinlbond
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Usemetaperl
 
Asp 3-html helpers in asp.net
Asp 3-html helpers in asp.netAsp 3-html helpers in asp.net
Asp 3-html helpers in asp.netFajar Baskoro
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database ProgrammingAhmed Swilam
 
Practical TypeScript
Practical TypeScriptPractical TypeScript
Practical TypeScriptldaws
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiiOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiMarin Benčević
 
Isset(), unset(), empty() 4
Isset(), unset(), empty()   4Isset(), unset(), empty()   4
Isset(), unset(), empty() 4Reed Crouch
 

La actualidad más candente (15)

Strings
StringsStrings
Strings
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 
Rakudo
RakudoRakudo
Rakudo
 
PHP variables
PHP  variablesPHP  variables
PHP variables
 
Dubles de teste
Dubles de testeDubles de teste
Dubles de teste
 
Macro Copy Paste Special Value Vba
Macro   Copy Paste Special Value   VbaMacro   Copy Paste Special Value   Vba
Macro Copy Paste Special Value Vba
 
Constructive Destructor Use
Constructive Destructor UseConstructive Destructor Use
Constructive Destructor Use
 
Asp 3-html helpers in asp.net
Asp 3-html helpers in asp.netAsp 3-html helpers in asp.net
Asp 3-html helpers in asp.net
 
Class 8 - Database Programming
Class 8 - Database ProgrammingClass 8 - Database Programming
Class 8 - Database Programming
 
003 scripting
003 scripting003 scripting
003 scripting
 
Practical TypeScript
Practical TypeScriptPractical TypeScript
Practical TypeScript
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Web 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHPWeb 11 | AJAX + JSON + PHP
Web 11 | AJAX + JSON + PHP
 
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksiiOS Talks 1 - CodeCamp Osijek - Swift u praksi
iOS Talks 1 - CodeCamp Osijek - Swift u praksi
 
Isset(), unset(), empty() 4
Isset(), unset(), empty()   4Isset(), unset(), empty()   4
Isset(), unset(), empty() 4
 

Similar a Implicit classes - share the knowledge

The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala MakeoverGarth Gilmour
 
Unit Test and TDD
Unit Test and TDDUnit Test and TDD
Unit Test and TDDViet Tran
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con djangoTomás Henríquez
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme SwiftMovel
 
Say Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick SuttererSay Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick SuttererRuby Meditation
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumansNarendran R
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212Mahmoud Samir Fayed
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patternsTomasz Kowal
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003R696
 
Iterative architecture
Iterative architectureIterative architecture
Iterative architectureJoshuaRizzo4
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportAnton Arhipov
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con GroovySoftware Guru
 

Similar a Implicit classes - share the knowledge (20)

The Great Scala Makeover
The Great Scala MakeoverThe Great Scala Makeover
The Great Scala Makeover
 
Clean Code
Clean CodeClean Code
Clean Code
 
Unit Test and TDD
Unit Test and TDDUnit Test and TDD
Unit Test and TDD
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Say Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick SuttererSay Goodbye to Procedural Programming - Nick Sutterer
Say Goodbye to Procedural Programming - Nick Sutterer
 
Write codeforhumans
Write codeforhumansWrite codeforhumans
Write codeforhumans
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212The Ring programming language version 1.10 book - Part 17 of 212
The Ring programming language version 1.10 book - Part 17 of 212
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Very basic functional design patterns
Very basic functional design patternsVery basic functional design patterns
Very basic functional design patterns
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Iterative architecture
Iterative architectureIterative architecture
Iterative architecture
 
NetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience ReportNetBeans Plugin Development: JRebel Experience Report
NetBeans Plugin Development: JRebel Experience Report
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Desarrollo para Android con Groovy
Desarrollo para Android con GroovyDesarrollo para Android con Groovy
Desarrollo para Android con Groovy
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Namespaces
NamespacesNamespaces
Namespaces
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Refactoring
RefactoringRefactoring
Refactoring
 

Último

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile EnvironmentVictorSzoltysek
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Último (20)

WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Implicit classes - share the knowledge

  • 1. Implicit classes Almost as beautiful as Trump’s hair
  • 3. Why? result match { case Success(_) => case Failure(ex) => Logger.error(s"Failed to comment project ${project.id}”) } I HATE BOILERPLATE result.logException(s"Failed to comment project ${project.id}”) And even logs the exception, that sometimes we love to hide...
  • 4. Implementation implicit class TryExtension[T](nativeTry: Try[T]) { private val defaultMsg: String = "Try is a failure" def logException(logger: String => Unit = defaultLogger, msg: String = defaultMsg): Try[T] = { nativeTry match { case Success(_) => nativeTry case Failure(e) => val msgWithStacktrace = s""" |$msg |message: ${e.getMessage} |${e.getStackTrace.mkString(System.lineSeparator)} """.stripMargin logger(msgWithStacktrace) nativeTry } } private def defaultLogger(msgWithStacktrace: String): Unit = Logger.error(msgWithStacktrace) }
  • 5. Although it uses “implicit”, remember that you still have to call the methods explicitly! So the “hate on implicits” arguments don’t apply ;)
  • 6. It’s not about knowing how to do it, it is about doing it! Instead of copypasta more bolierplate.. .orElse { Logger.error(s"Failed to updated Heroku user: RequestURL=$url Response=${response.json}") None } Pretty much as we did a .logException(), we can easily do a .logNone()! .logNone(s"Failed to updated Heroku user: RequestURL=$url Response=${response.json}")
  • 7. It can be more than just logs Although I like to use the extensions on logs, (because we don’t care about them, we just want the bad guys to be logged, and it always the same thing) there are MANY MORE cases where we can use them. if (!updated) { ProjectRules.addUserToProject( projectId, teamMember.userIdentifier, teamMember.permission ) } updated
  • 8. Boolean Extension :D updated.onFalse { ProjectRules.addUserToProject( projectId, teamMember.userIdentifier, teamMember.permission ) } updated //not needed .onFalse() returns the boolean itself, so no need to repeat the “updated”
  • 9. Plenty of great use cases! //potatos: Seq[A] potatos.distinctBy(_.weight) //Instead of CollectionHelper.distinctBy(potatos, _.weight) //res: Option[A] res.toResponse(msg = “Failed xxx”) //res: Try[A] res.toResponse() …….
  • 10. Implicit Classes Everywhere??? The “Extension” types are just a way to achieve extension methods. Never use their types! For example “TryExtension” should only be mentioned on the import itself, shouldn’t be use anywhere else! We just want the methods, not the type of the class And also, PLEASE don’t do implicit extensions on classes that we own! If if is our code, we can just go there and add a method! “Don’t wanna update foundation” is not an excuse to start making implicit classes that extend our Response!
  • 11. “he who yields the chalice shall have everlasting awesomeness” - The ancient council of elders
  • 12. Thank you! João Machado machado@codacy.com https://github.com/machadoit Meet our team at: https://www.codacy.com Review less, merge faster Check code style, security, duplication, complexity and coverage on every change while tracking code quality throughout your sprints.

Notas del editor

  1. Even if it isn’t much, that are stuff that we do often enough, that is really bad to not have an easy way to do it