Today I Learned

hashrocket A Hashrocket project

Pattern Match and ++ operator

Today I learned that ++ operator should not be used on pattern matching.

This works with Lists of integers, but fails on compilation time for other content type.

[1] ++ [2] = [1, 2] #=> [1, 2]

[:foo] ++ [:bar] = [:foo, :bar] #=> ** (CompileError): illegal pattern
[foo: 1] ++ [bar: 2] = [foo: 1, bar: 2] #=> ** (CompileError): illegal pattern
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.