{"action":"created","comment":{"url":"https://api.github.com/repos/willb/silex/pulls/comments/36427373","id":36427373,"diff_hunk":"@@ -0,0 +1,112 @@\n+/*\n+ * This file is part of the \"silex\" library of helpers for Apache Spark.\n+ *\n+ * Copyright (c) 2015 Red Hat, Inc.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.c\n+ */\n+\n+package com.redhat.et.silex.util\n+\n+/**\n+ * Provides idiomatic optional parameter values on top of [[Option]], but which can be passed in as\n+ * raw values, instead of having to pass in Some(value)\n+ * {{{\n+ * import com.redhat.et.silex.util.OptionalArg\n+ *\n+ * def possiblyFilter(data: Seq[Int], filterMax: OptionalArg[Int] = None) = {\n+ *   // Treat an OptionalArg like an Option, for idiomatic handling of unset vals as None\n+ *   if (filterMax.isEmpty) data else data.filter(_ <= filterMax.get)\n+ * }\n+ *\n+ * val data = Seq(1, -1, 2)\n+ *\n+ * // default filterMax is None\n+ * possiblyFilter(data) // returns data unfiltered\n+ *\n+ * // provide argument as (-1), instead of having to specify Some(-1)\n+ * possiblyFilter(data, filterMax = -1) // returns Seq(-1)\n+ *\n+ * // Support full Option methods and implicit conversion to Option\n+ * import OptionalArg.fullOptionSupport\n+ * OptionalArg(\"xxx\").map(_ + \"zzz\").get // returns \"xxxzzz\"\n+ * }}}\n+ *\n+ * @tparam A The underlying value type.\n+ * @param option The raw Option value.  May be implicitly constructed from raw value of type A\n+ */\n+class OptionalArg[+A](val option: Option[A]) extends AnyVal {\n+  /** Determine if the optional argument is empty (contains None)\n+   * @return true if the option is None, false otherwise\n+   */\n+  def isEmpty = option.isEmpty\n+\n+  /** Determine if the optional argument is defined (contains Some(value))\n+   * @return true if option contains Some(value), false otherwise\n+   */\n+  def isDefined = option.isDefined\n+\n+  /** Get the value of the optional argument, assuming the argument is not empty.\n+   * @return the value of the optional argument, or throw an exception if it is None\n+   */\n+  def get = option.get\n+\n+  /** Get the value of the optional argument if it is defined, otherwise return the given default.\n+   * @param d A block evaluating to a default value, if the the optional value is not defined\n+   * @return The value of the optional argument if one was defined, otherwise the value of d\n+   */\n+  def getOrElse[A1 >: A](d: => A1): A1 = option.getOrElse(d)","path":"src/main/scala/com/redhat/et/silex/util/optionalArg.scala","position":68,"original_position":68,"commit_id":"4785372e836727c4ad4da25e36c98fab8b5fcdc1","original_commit_id":"4785372e836727c4ad4da25e36c98fab8b5fcdc1","user":{"login":"erikerlandson","id":259898,"avatar_url":"https://avatars.githubusercontent.com/u/259898?v=3","gravatar_id":"","url":"https://api.github.com/users/erikerlandson","html_url":"https://github.com/erikerlandson","followers_url":"https://api.github.com/users/erikerlandson/followers","following_url":"https://api.github.com/users/erikerlandson/following{/other_user}","gists_url":"https://api.github.com/users/erikerlandson/gists{/gist_id}","starred_url":"https://api.github.com/users/erikerlandson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikerlandson/subscriptions","organizations_url":"https://api.github.com/users/erikerlandson/orgs","repos_url":"https://api.github.com/users/erikerlandson/repos","events_url":"https://api.github.com/users/erikerlandson/events{/privacy}","received_events_url":"https://api.github.com/users/erikerlandson/received_events","type":"User","site_admin":false},"body":"In this case, it was just because that is how Option's type signature looks.  Not exactly sure why.  I saw something similar with signature of `unioned` for HashMap.","created_at":"2015-08-06T15:23:41Z","updated_at":"2015-08-06T15:23:41Z","html_url":"https://github.com/willb/silex/pull/25#discussion_r36427373","pull_request_url":"https://api.github.com/repos/willb/silex/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/willb/silex/pulls/comments/36427373"},"html":{"href":"https://github.com/willb/silex/pull/25#discussion_r36427373"},"pull_request":{"href":"https://api.github.com/repos/willb/silex/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/willb/silex/pulls/25","id":41488934,"html_url":"https://github.com/willb/silex/pull/25","diff_url":"https://github.com/willb/silex/pull/25.diff","patch_url":"https://github.com/willb/silex/pull/25.patch","issue_url":"https://api.github.com/repos/willb/silex/issues/25","number":25,"state":"open","locked":false,"title":"Implement OptionalArg","user":{"login":"erikerlandson","id":259898,"avatar_url":"https://avatars.githubusercontent.com/u/259898?v=3","gravatar_id":"","url":"https://api.github.com/users/erikerlandson","html_url":"https://github.com/erikerlandson","followers_url":"https://api.github.com/users/erikerlandson/followers","following_url":"https://api.github.com/users/erikerlandson/following{/other_user}","gists_url":"https://api.github.com/users/erikerlandson/gists{/gist_id}","starred_url":"https://api.github.com/users/erikerlandson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikerlandson/subscriptions","organizations_url":"https://api.github.com/users/erikerlandson/orgs","repos_url":"https://api.github.com/users/erikerlandson/repos","events_url":"https://api.github.com/users/erikerlandson/events{/privacy}","received_events_url":"https://api.github.com/users/erikerlandson/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-03T17:14:44Z","updated_at":"2015-08-06T15:23:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9d0d7572c08bbce7d2f50bbcade29701e61c6430","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/willb/silex/pulls/25/commits","review_comments_url":"https://api.github.com/repos/willb/silex/pulls/25/comments","review_comment_url":"https://api.github.com/repos/willb/silex/pulls/comments{/number}","comments_url":"https://api.github.com/repos/willb/silex/issues/25/comments","statuses_url":"https://api.github.com/repos/willb/silex/statuses/4785372e836727c4ad4da25e36c98fab8b5fcdc1","head":{"label":"erikerlandson:feature/optional","ref":"feature/optional","sha":"4785372e836727c4ad4da25e36c98fab8b5fcdc1","user":{"login":"erikerlandson","id":259898,"avatar_url":"https://avatars.githubusercontent.com/u/259898?v=3","gravatar_id":"","url":"https://api.github.com/users/erikerlandson","html_url":"https://github.com/erikerlandson","followers_url":"https://api.github.com/users/erikerlandson/followers","following_url":"https://api.github.com/users/erikerlandson/following{/other_user}","gists_url":"https://api.github.com/users/erikerlandson/gists{/gist_id}","starred_url":"https://api.github.com/users/erikerlandson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikerlandson/subscriptions","organizations_url":"https://api.github.com/users/erikerlandson/orgs","repos_url":"https://api.github.com/users/erikerlandson/repos","events_url":"https://api.github.com/users/erikerlandson/events{/privacy}","received_events_url":"https://api.github.com/users/erikerlandson/received_events","type":"User","site_admin":false},"repo":{"id":30730149,"name":"silex","full_name":"erikerlandson/silex","owner":{"login":"erikerlandson","id":259898,"avatar_url":"https://avatars.githubusercontent.com/u/259898?v=3","gravatar_id":"","url":"https://api.github.com/users/erikerlandson","html_url":"https://github.com/erikerlandson","followers_url":"https://api.github.com/users/erikerlandson/followers","following_url":"https://api.github.com/users/erikerlandson/following{/other_user}","gists_url":"https://api.github.com/users/erikerlandson/gists{/gist_id}","starred_url":"https://api.github.com/users/erikerlandson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/erikerlandson/subscriptions","organizations_url":"https://api.github.com/users/erikerlandson/orgs","repos_url":"https://api.github.com/users/erikerlandson/repos","events_url":"https://api.github.com/users/erikerlandson/events{/privacy}","received_events_url":"https://api.github.com/users/erikerlandson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/erikerlandson/silex","description":"something to help you spark","fork":true,"url":"https://api.github.com/repos/erikerlandson/silex","forks_url":"https://api.github.com/repos/erikerlandson/silex/forks","keys_url":"https://api.github.com/repos/erikerlandson/silex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/erikerlandson/silex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/erikerlandson/silex/teams","hooks_url":"https://api.github.com/repos/erikerlandson/silex/hooks","issue_events_url":"https://api.github.com/repos/erikerlandson/silex/issues/events{/number}","events_url":"https://api.github.com/repos/erikerlandson/silex/events","assignees_url":"https://api.github.com/repos/erikerlandson/silex/assignees{/user}","branches_url":"https://api.github.com/repos/erikerlandson/silex/branches{/branch}","tags_url":"https://api.github.com/repos/erikerlandson/silex/tags","blobs_url":"https://api.github.com/repos/erikerlandson/silex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/erikerlandson/silex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/erikerlandson/silex/git/refs{/sha}","trees_url":"https://api.github.com/repos/erikerlandson/silex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/erikerlandson/silex/statuses/{sha}","languages_url":"https://api.github.com/repos/erikerlandson/silex/languages","stargazers_url":"https://api.github.com/repos/erikerlandson/silex/stargazers","contributors_url":"https://api.github.com/repos/erikerlandson/silex/contributors","subscribers_url":"https://api.github.com/repos/erikerlandson/silex/subscribers","subscription_url":"https://api.github.com/repos/erikerlandson/silex/subscription","commits_url":"https://api.github.com/repos/erikerlandson/silex/commits{/sha}","git_commits_url":"https://api.github.com/repos/erikerlandson/silex/git/commits{/sha}","comments_url":"https://api.github.com/repos/erikerlandson/silex/comments{/number}","issue_comment_url":"https://api.github.com/repos/erikerlandson/silex/issues/comments{/number}","contents_url":"https://api.github.com/repos/erikerlandson/silex/contents/{+path}","compare_url":"https://api.github.com/repos/erikerlandson/silex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/erikerlandson/silex/merges","archive_url":"https://api.github.com/repos/erikerlandson/silex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/erikerlandson/silex/downloads","issues_url":"https://api.github.com/repos/erikerlandson/silex/issues{/number}","pulls_url":"https://api.github.com/repos/erikerlandson/silex/pulls{/number}","milestones_url":"https://api.github.com/repos/erikerlandson/silex/milestones{/number}","notifications_url":"https://api.github.com/repos/erikerlandson/silex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/erikerlandson/silex/labels{/name}","releases_url":"https://api.github.com/repos/erikerlandson/silex/releases{/id}","created_at":"2015-02-12T23:05:58Z","updated_at":"2015-02-12T23:05:58Z","pushed_at":"2015-08-03T17:13:57Z","git_url":"git://github.com/erikerlandson/silex.git","ssh_url":"git@github.com:erikerlandson/silex.git","clone_url":"https://github.com/erikerlandson/silex.git","svn_url":"https://github.com/erikerlandson/silex","homepage":null,"size":793,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"willb:develop","ref":"develop","sha":"c9bb44d906132268292adbd3daf8066b76b44f11","user":{"login":"willb","id":1161,"avatar_url":"https://avatars.githubusercontent.com/u/1161?v=3","gravatar_id":"","url":"https://api.github.com/users/willb","html_url":"https://github.com/willb","followers_url":"https://api.github.com/users/willb/followers","following_url":"https://api.github.com/users/willb/following{/other_user}","gists_url":"https://api.github.com/users/willb/gists{/gist_id}","starred_url":"https://api.github.com/users/willb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willb/subscriptions","organizations_url":"https://api.github.com/users/willb/orgs","repos_url":"https://api.github.com/users/willb/repos","events_url":"https://api.github.com/users/willb/events{/privacy}","received_events_url":"https://api.github.com/users/willb/received_events","type":"User","site_admin":false},"repo":{"id":30727293,"name":"silex","full_name":"willb/silex","owner":{"login":"willb","id":1161,"avatar_url":"https://avatars.githubusercontent.com/u/1161?v=3","gravatar_id":"","url":"https://api.github.com/users/willb","html_url":"https://github.com/willb","followers_url":"https://api.github.com/users/willb/followers","following_url":"https://api.github.com/users/willb/following{/other_user}","gists_url":"https://api.github.com/users/willb/gists{/gist_id}","starred_url":"https://api.github.com/users/willb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willb/subscriptions","organizations_url":"https://api.github.com/users/willb/orgs","repos_url":"https://api.github.com/users/willb/repos","events_url":"https://api.github.com/users/willb/events{/privacy}","received_events_url":"https://api.github.com/users/willb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/willb/silex","description":"something to help you spark","fork":false,"url":"https://api.github.com/repos/willb/silex","forks_url":"https://api.github.com/repos/willb/silex/forks","keys_url":"https://api.github.com/repos/willb/silex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/willb/silex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/willb/silex/teams","hooks_url":"https://api.github.com/repos/willb/silex/hooks","issue_events_url":"https://api.github.com/repos/willb/silex/issues/events{/number}","events_url":"https://api.github.com/repos/willb/silex/events","assignees_url":"https://api.github.com/repos/willb/silex/assignees{/user}","branches_url":"https://api.github.com/repos/willb/silex/branches{/branch}","tags_url":"https://api.github.com/repos/willb/silex/tags","blobs_url":"https://api.github.com/repos/willb/silex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/willb/silex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/willb/silex/git/refs{/sha}","trees_url":"https://api.github.com/repos/willb/silex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/willb/silex/statuses/{sha}","languages_url":"https://api.github.com/repos/willb/silex/languages","stargazers_url":"https://api.github.com/repos/willb/silex/stargazers","contributors_url":"https://api.github.com/repos/willb/silex/contributors","subscribers_url":"https://api.github.com/repos/willb/silex/subscribers","subscription_url":"https://api.github.com/repos/willb/silex/subscription","commits_url":"https://api.github.com/repos/willb/silex/commits{/sha}","git_commits_url":"https://api.github.com/repos/willb/silex/git/commits{/sha}","comments_url":"https://api.github.com/repos/willb/silex/comments{/number}","issue_comment_url":"https://api.github.com/repos/willb/silex/issues/comments{/number}","contents_url":"https://api.github.com/repos/willb/silex/contents/{+path}","compare_url":"https://api.github.com/repos/willb/silex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/willb/silex/merges","archive_url":"https://api.github.com/repos/willb/silex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/willb/silex/downloads","issues_url":"https://api.github.com/repos/willb/silex/issues{/number}","pulls_url":"https://api.github.com/repos/willb/silex/pulls{/number}","milestones_url":"https://api.github.com/repos/willb/silex/milestones{/number}","notifications_url":"https://api.github.com/repos/willb/silex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/willb/silex/labels{/name}","releases_url":"https://api.github.com/repos/willb/silex/releases{/id}","created_at":"2015-02-12T22:24:36Z","updated_at":"2015-08-06T03:44:40Z","pushed_at":"2015-08-03T17:14:45Z","git_url":"git://github.com/willb/silex.git","ssh_url":"git@github.com:willb/silex.git","clone_url":"https://github.com/willb/silex.git","svn_url":"https://github.com/willb/silex","homepage":null,"size":1461,"stargazers_count":8,"watchers_count":8,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":5,"mirror_url":null,"open_issues_count":8,"forks":5,"open_issues":8,"watchers":8,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/willb/silex/pulls/25"},"html":{"href":"https://github.com/willb/silex/pull/25"},"issue":{"href":"https://api.github.com/repos/willb/silex/issues/25"},"comments":{"href":"https://api.github.com/repos/willb/silex/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/willb/silex/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/willb/silex/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/willb/silex/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/willb/silex/statuses/4785372e836727c4ad4da25e36c98fab8b5fcdc1"}}}}