Skip to content

x87-va/erroico

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

erroico

Haskell do syntax and Error monad extension for Erlang. Implemented as Parse Transform.

Usage

  1. add to deps in rebar.conf:
{erroico, ".*", {git, "https://github.com/Tpukep/erroico", "master"}} 
  1. Include erroico definitions in your module:
-include_lib("erroico/include/erroico.hrl").

Example

-module(erroico_demo).

-include_lib("erroico/include/erroico.hrl").

-export([info_update/2]).

fetch_info(UserId, Token) ->
    %% try to fetch from some data source and fail
    {error, "Fetch error"}.
    %% {ok, "Some info"}.

modify_info(Info) ->
	%% some processing here
	{ok, Info}.

save_info(UserId, NewInfo) ->
	%% save new info
	{ok, {UserId, saved}}.

info_update(UserId, Token) ->
    do(begin
        Info = fetch_info(UserId, Token),
        NewInfo = modify_info(Info),
        save_info(UserId, NewInfo)
    end).
1> erroico_demo:info_update("demoUser", "token").
{error, "Fetch error"}

When error result({error, Reason}) is returned by some function in do block rest functions are ignored and error result is returned. If no error occured then all functions will be executed in the block and success result({ok, Result}) will be returned. Try comment error result and uncomment success result in fetch_info function.

2> erroico_demo:info_update("demoUser", "token").
{ok,{"demoUser",saved}}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages