{"action":"created","issue":{"url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/3","labels_url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/3/comments","events_url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/3/events","html_url":"https://github.com/Kevin-Lee/j8plus/issues/3","id":86597880,"number":3,"title":"There should be an easy way to use any given value depending on any given condition.","user":{"login":"Kevin-Lee","id":2307335,"avatar_url":"https://avatars.githubusercontent.com/u/2307335?v=3","gravatar_id":"","url":"https://api.github.com/users/Kevin-Lee","html_url":"https://github.com/Kevin-Lee","followers_url":"https://api.github.com/users/Kevin-Lee/followers","following_url":"https://api.github.com/users/Kevin-Lee/following{/other_user}","gists_url":"https://api.github.com/users/Kevin-Lee/gists{/gist_id}","starred_url":"https://api.github.com/users/Kevin-Lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kevin-Lee/subscriptions","organizations_url":"https://api.github.com/users/Kevin-Lee/orgs","repos_url":"https://api.github.com/users/Kevin-Lee/repos","events_url":"https://api.github.com/users/Kevin-Lee/events{/privacy}","received_events_url":"https://api.github.com/users/Kevin-Lee/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Kevin-Lee/j8plus/labels/task","name":"task","color":"207de5"}],"state":"closed","locked":false,"assignee":{"login":"Kevin-Lee","id":2307335,"avatar_url":"https://avatars.githubusercontent.com/u/2307335?v=3","gravatar_id":"","url":"https://api.github.com/users/Kevin-Lee","html_url":"https://github.com/Kevin-Lee","followers_url":"https://api.github.com/users/Kevin-Lee/followers","following_url":"https://api.github.com/users/Kevin-Lee/following{/other_user}","gists_url":"https://api.github.com/users/Kevin-Lee/gists{/gist_id}","starred_url":"https://api.github.com/users/Kevin-Lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kevin-Lee/subscriptions","organizations_url":"https://api.github.com/users/Kevin-Lee/orgs","repos_url":"https://api.github.com/users/Kevin-Lee/repos","events_url":"https://api.github.com/users/Kevin-Lee/events{/privacy}","received_events_url":"https://api.github.com/users/Kevin-Lee/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/Kevin-Lee/j8plus/milestones/2","html_url":"https://github.com/Kevin-Lee/j8plus/milestones/0.0.11","labels_url":"https://api.github.com/repos/Kevin-Lee/j8plus/milestones/2/labels","id":1156792,"number":2,"title":"0.0.11","description":null,"creator":{"login":"Kevin-Lee","id":2307335,"avatar_url":"https://avatars.githubusercontent.com/u/2307335?v=3","gravatar_id":"","url":"https://api.github.com/users/Kevin-Lee","html_url":"https://github.com/Kevin-Lee","followers_url":"https://api.github.com/users/Kevin-Lee/followers","following_url":"https://api.github.com/users/Kevin-Lee/following{/other_user}","gists_url":"https://api.github.com/users/Kevin-Lee/gists{/gist_id}","starred_url":"https://api.github.com/users/Kevin-Lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kevin-Lee/subscriptions","organizations_url":"https://api.github.com/users/Kevin-Lee/orgs","repos_url":"https://api.github.com/users/Kevin-Lee/repos","events_url":"https://api.github.com/users/Kevin-Lee/events{/privacy}","received_events_url":"https://api.github.com/users/Kevin-Lee/received_events","type":"User","site_admin":false},"open_issues":0,"closed_issues":1,"state":"open","created_at":"2015-06-09T13:21:48Z","updated_at":"2015-06-09T14:08:06Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2015-06-09T13:21:16Z","updated_at":"2015-06-09T14:13:31Z","closed_at":"2015-06-09T14:08:06Z","body":"There should be an easy way to use any given value depending on any given condition. It if the given predicate is satisfied using the given value, it use the value. Otherwise, it uses the given alternative value. Calculation or evaluation of the alternative value might be expensive so it should be lazily evaluated if and only if it is required.\r\n\r\nSo the call site looks like,\r\n\r\n```java\r\nfinal Integer num1 = 5;\r\n\r\nfinal Integer result1 = useIfSatisfy(num1, i -> i > 0, () -> 1);  // result: 5 as 5 is greater than 0.\r\nfinal Integer result2 = useIfSatisfy(num1, i -> i < 0, () -> -1); // result: -1 as 5 is NOT less than 0 so it uses\r\n                                                                  //         the alternative returned from the given function (lazily evaluated).\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/comments/110368520","html_url":"https://github.com/Kevin-Lee/j8plus/issues/3#issuecomment-110368520","issue_url":"https://api.github.com/repos/Kevin-Lee/j8plus/issues/3","id":110368520,"user":{"login":"Kevin-Lee","id":2307335,"avatar_url":"https://avatars.githubusercontent.com/u/2307335?v=3","gravatar_id":"","url":"https://api.github.com/users/Kevin-Lee","html_url":"https://github.com/Kevin-Lee","followers_url":"https://api.github.com/users/Kevin-Lee/followers","following_url":"https://api.github.com/users/Kevin-Lee/following{/other_user}","gists_url":"https://api.github.com/users/Kevin-Lee/gists{/gist_id}","starred_url":"https://api.github.com/users/Kevin-Lee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kevin-Lee/subscriptions","organizations_url":"https://api.github.com/users/Kevin-Lee/orgs","repos_url":"https://api.github.com/users/Kevin-Lee/repos","events_url":"https://api.github.com/users/Kevin-Lee/events{/privacy}","received_events_url":"https://api.github.com/users/Kevin-Lee/received_events","type":"User","site_admin":false},"created_at":"2015-06-09T14:13:31Z","updated_at":"2015-06-09T14:13:31Z","body":"An alternative to this might be using `Optional` type.\r\ne.g.)\r\n```java\r\nfinal Integer result1 = Optional.ofNullable(5).filter(i -> i > 0).orElseGet(() -> 1);  // result: 5 as 5 is greater than 0.\r\nfinal Integer result2 = Optional.ofNullable(5).filter(i -> i < 0).orElseGet(() -> -1); // result: -1 as 5 is NOT less than 0 so it uses\r\n                                                                                 //         the alternative returned from the given function (lazily evaluated).\r\n```"}}