specter 2020-12-21

Hi, is there a way to distinguish between a path not found and a path-value with nil? like get-in with default value?

(get-in {"foo" nil} ["foo"] :not-found) ;;=> nil
(get-in {"bar" nil} ["foo"] :not-found) ;;=> :not-found
(select ["foo"] {"foo" nil}) ;;=> [nil]
(select ["bar"] {"foo" nil}) ;;=> [nil]

@bruno.bonacci use the must navigator

ok, however must uses contains? which fails if it not a map

so i have to put a guard predicate on every nesting to check that is a map

like [(pred map?) (must "foo") (pred map?) (must "bar") (pred map?) (must "baz")]

example: (get-in {"foo" 1} ["foo" "bar"] :not-found) ;;=> :not-found (select [(must "foo") (must "bar")] {"foo" 1}) throws: Execution error (IllegalArgumentException) at com.rpl.specter.navs$fn$reify__33786/select_STAR_ (navs.cljc:655). contains? not supported on type: java.lang.Long

personally I think it's a good thing specter throws an exception in that case

🙌 1

but you can always write your own navigator with the more lenient behavior

👍 1