DEV Community

Adam Cervenka
Adam Cervenka

Posted on

Scala Tip: appending a sequence optionally

If you want to add option's content to a sequence, you can easily do that using ++ or appendAll method.

Image 2021-07-29 at 15.18.26

This is possible because ++ expects collection and there is an implicit conversion from an option to collection in Scala.

But be careful with :+ because that expects just one element and no conversion will be applied and this happens:

Image 2021-07-29 at 15.21.13

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay