The Rogue Wave

Steve and his crew have already loaded the boat and untied the ropes from the dock. As their boat putters out of the marina before the sunrises, a stiff morning breeze blows over the deck. The crew…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Elixir and Behaviours by Ecto example

An Elixir behaviour is just a list of functions. A module that declares that it implements a particular behaviour must implement all of these functions.

I would say that behaviours are kind of interfaces from the OOP world.

Illustration by Peter Justin Gerard

So if you want to use custom types then you should implement all of these 4 functions: type, cast, load and dump. Otherwise, Elixir will throw a compilation warning.

@behaviour declares that Arc.Ecto.Definition implements Ecto.Type and then defines necessary functions.

Then you can use Arc’s custom type in your app:

That’s all for today.
Thank you for reading this post!

Add a comment

Related posts:

Oath

Matchbox Quotes Day 36 [2018–02–03]. “Oath” is published by Tre L. Loadholt in Scene & Heard (SNH).

Summary

One of the many problems that plenty of low-income neighborhoods have faced is gentrification. Through time and time again, many low-income families are getting evicted due to rent exponentially…

Embracing Gender and Sexuality Diversity

Given how pervasively political, cultural, educational, and religious institutions are built on a foundation of stereotypes and binary assumptions, it is easy to understand why people find the…