Last active
December 28, 2015 09:18
-
-
Save jsvd/7477358 to your computer and use it in GitHub Desktop.
1) receive event string
2) split header and payload
3) transform each in a wellformed list of fields
4) return their concatenation or an error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format event | |
{header, payload} = SomeModule.somefn(event) | |
# then return the concatenation of the resulting lists | |
{:ok, format_header(header) ++ format_payload(payload)} | |
# or | |
{:error, format_header_reason} | |
# or | |
{:error, format_payload_reason} | |
end | |
def format_header(header) | |
# do stuff | |
.... | |
# and return | |
{:ok, ["a", "b", "c"]} | |
# or | |
{:error, "Header Parse Failed"} | |
end | |
def format_payload(payload) | |
# do stuff | |
.... | |
# and return | |
{:ok, [1, 2, 3, 4, 5, 6, 7]} | |
# or | |
{:error, "Payload Parse Failed"} | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format event | |
{header, payload} = SomeModule.somefn(event) | |
case format_header(header) do | |
{:ok, f_header} -> | |
case format_payload(payload) do | |
{:ok, f_payload} -> {:ok, f_header ++ f_payload} | |
{:error, reason -> {:error, reason} | |
end | |
{:error, reason -> {:error, reason} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment