Fork me on GitHub
#malli
<
2022-06-06
>
Tiago Dall'Oca12:06:10

Hello hello! Is there a generics implemented in malli in some way? I was thinking maybe e.g. [:generic=> [:n-type number?] [:cat :n-type] [:vector :n-type]], :generic=> taking a vector of pairs of keywords and schemas and then the usual :=> args

Noah Bogart13:06:26

All clojure functions are generic, lol

Tiago Dall'Oca15:06:41

the idea is to parse malli schemas to ts type definitions

Tiago Dall'Oca15:06:53

to make cljs libraries nicer to consume from ts

Noah Bogart15:06:11

Sorry, I replied with a cheeky comment but I meant to follow up: clojure inherently doesn't have generics and while I don't want to speak for the metosin folks, i suspect that the concept of "generics" fundamentally doesn't align with schema systems like malli. you can already achieve generics by just using :or and normal clojure functions: [:or (mapv #(do [:=> [:cat %] [:vector %]]) [number? keyword? string?])]

Noah Bogart15:06:27

having said that, iwould be interested to see what you could build in this space as i think it has potential. it's cool to see the overlap between clojure schema systems and typescript's structural typing

Ben Sless16:06:44

Simple schema can take an argument, make it the type

Tiago Dall'Oca12:06:27

malli positively surprising me as usual

Tiago Dall'Oca12:06:43

thank you all for the excellent work!

Tiago Dall'Oca12:06:52

I'm developing mali-ts as a way to integrate malli schemas into typescript's type system and it'd be really good to have generics, though I understand why in clojure it might not make so much sense

Tiago Dall'Oca12:06:16

Maybe it's not even that hard to implement? I'm not sure

Tiago Dall'Oca12:06:09

And on the topic typescript integration, it'd be really good to have a way to model Promises and async stuff

Ben Sless16:06:29

If you have generics modeled then promises are solves, no?

Tiago Dall'Oca12:06:44

If doesn't make sense to have those in malli, I might implement in malli-ts only

👍 1