Implementing Agents using GenServer

Boobalan AP
Dec 24, 2020

--

Agent is an abstraction over GenServer. It is used when we want to store and retrieve only the data from the process without doing any additional logic.

  1. On start we initialize the state. We pass a function and the return value of it is assigned to the initial state.
  2. If we want to retrieve the state, we pass a function which takes state as parameter and manipulates it to return back what and how we want.
  3. If we want to update the state, again a function is passed which takes parameter as list and the return value of the function is assigned to the state.

Check my book for Elixir starters at https://gum.co/XgbKSE

--

--

Boobalan AP
Boobalan AP

No responses yet