Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a from optional function #6

Closed
CrowdHailer opened this issue Dec 28, 2016 · 5 comments
Closed

Add a from optional function #6

CrowdHailer opened this issue Dec 28, 2016 · 5 comments

Comments

@CrowdHailer
Copy link
Owner

{:ok, value} = OK.optional(value)
{:error, :none} = OK.optional(nil)

perhaps provide reason

{:error, reason} = OK.optional(nil, reason: :needs_value)

port = OK.optional(Map.get(config, "port"), reason)
@CrowdHailer
Copy link
Owner Author

When this is added we should handle the case of a single line inside the block.

OK.try do
  perform(action)
else
  %ArgumentError{} ->
    {:error, %BadRequest{}}
end

@CrowdHailer
Copy link
Owner Author

call required not optional

@ghost
Copy link

ghost commented Jan 13, 2017

So perhaps your port example could look like this?

port = 
  config
  |> Map.get("port")
  |> OK.required(reason: :needs_value)

@CrowdHailer
Copy link
Owner Author

I like that.

@CrowdHailer
Copy link
Owner Author

Added in PR #26, check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant