malli

richiardiandrea 2025-01-24T23:04:24.523019Z

Hi folks - was wondering if there is a way to extract the type from a vector inside :maybe Currently this does: (m/type [:maybe [:enum "foo"]]) ;;=> :maybe Is there a way to get :enum instead?

2025-01-24T23:48:20.476409Z

user=> (-> [:maybe [:enum "foo"]] (mu/get 0) m/type)
:enum

richiardiandrea 2025-01-24T23:48:57.550059Z

yeah that means though I have to go nested only if :maybe is there

richiardiandrea 2025-01-24T23:49:48.795039Z

I guess I though I could somehow distinguish between an type schema and a "meta" schema (I guess there is a better name for those)

2025-01-24T23:51:53.431069Z

yes you'll need to write an algorithm that discards each schema you consider superfluous

richiardiandrea 2025-01-24T23:52:07.036109Z

yep

richiardiandrea 2025-01-24T23:52:16.143259Z

thank you for validating that 😄

richiardiandrea 2025-01-24T23:52:44.008339Z

found malli.util/find-first and I am using that

2025-01-24T23:55:27.116729Z

seems sufficient for unwrapping :maybe . you might want to m/deref-all at each step to resolve refs.

👍 1
➕ 1
richiardiandrea 2025-01-24T23:55:54.960639Z

didn't think about that thanks

2025-01-24T23:58:16.298649Z

gets a bit awkward with find-first because you can't tell it to continue with the deref'd schema. maybe something simpler like a recursive fn with a case is better.

2025-01-24T23:59:06.698379Z

(fn rec [s] 
  (let [s (m/deref-all s)]
    (case (m/type s)
      :maybe (rec (mu/get s 0))
      s)))

❤️ 1
richiardiandrea 2025-01-24T23:59:33.829329Z

oh nice thank you!

richiardiandrea 2025-01-24T23:59:41.312499Z

this definitely gets me going

2025-01-24T23:59:46.503029Z

good luck!

🙏 1