Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to correctly assert struct type in elixir

I know you can assert a type struct like this (althought its more a module assert):

assert foo.__struct__ == Foo

But is there a more elegant way to do this? something like:

assert type(foo) == %Foo{}
like image 459
lapinkoira Avatar asked Apr 19 '18 14:04

lapinkoira


1 Answers

You can use = and pattern matching:

assert %Foo{} = foo
like image 120
Dogbert Avatar answered Oct 24 '22 08:10

Dogbert