;; -?>> can be used if intermediate forms may potentially return nil.
;; This is to prevent
user=> (use '[clojure.contrib.core :only (-?>>)])
nil
;; create function that will return nil if the passed value is "Hello"
user=> (defn return-nil-for-hello [str-value]
(if (= str-value "Hello")
nil
str-value))
#'user/return-nil
user=> (->> "Greetings" return-nil-for-hello .toUpperCase)
"GREETINGS"
;; null pointer exception is thrown because return-nil-for-hello
;; returns nil and method .toUpperCase cannot process nil
user=> (->> "Hello" return-nil-for-hello .toUpperCase)
NullPointerException clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:314)
;; using -?>> will prevent null exception thrown
user=> (-?>> "Hello" return-nil-for-hello .toUpperCase)
nil
;; -?>> can be used if intermediate forms may potentially return nil.
;; This is to prevent
user=> (use '[clojure.contrib.core :only (-?>>)])
nil
;; create function that will return nil if the passed value is "Hello"
user=> (defn return-nil-for-hello [str-value]
(if (= str-value "Hello")
nil
str-value))
#'user/return-nil
user=> (->> "Greetings" return-nil-for-hello .toUpperCase)
"GREETINGS"
;; null pointer exception is thrown because return-nil-for-hello
;; returns nil and method .toUpperCase cannot process nil
user=> (->> "Hello" return-nil-for-hello .toUpperCase)
NullPointerException clojure.lang.Reflector.invokeNoArgInstanceMember (Reflector.java:314)
;; using -?>> will prevent null exception thrown
user=> (-?>> "Hello" return-nil-for-hello .toUpperCase)
nil