specter

Latest version: 1.1.3
2020-12-21T12:18:40.046300Z

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]

nathanmarz 2020-12-21T17:29:20.046800Z

@bruno.bonacci use the must navigator

2020-12-21T17:30:29.047400Z

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

2020-12-21T17:31:29.048200Z

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

2020-12-21T17:32:36.049100Z

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

2020-12-21T17:37:21.051100Z

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

nathanmarz 2020-12-21T18:00:34.051400Z

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

nathanmarz 2020-12-21T18:00:44.051700Z

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

👍 1