Skip to content

Instantly share code, notes, and snippets.

@lagenorhynque
Created December 8, 2017 04:51
Show Gist options
  • Select an option

  • Save lagenorhynque/5d42b5cbb32f6ea034a041f03984c0df to your computer and use it in GitHub Desktop.

Select an option

Save lagenorhynque/5d42b5cbb32f6ea034a041f03984c0df to your computer and use it in GitHub Desktop.
> maybe "undefined" (show . (^ 2)) (Just 42)
"1764"
> maybe "undefined" (show . (^ 2)) Nothing
"undefined"
user=> (if-let [x 42] (str (* x x)) "undefined")
"1764"
user=> (if-let [x nil] (str (* x x)) "undefined")
"undefined"
scala> (Some(42): Option[Int]).fold("undefined")(n => (n * n).toString)
res0: String = 1764
scala> (None: Option[Int]).fold("undefined")(n => (n * n).toString)
res1: String = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment