This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-12
Channels
- # adventofcode (49)
- # announcements (22)
- # beginners (33)
- # calva (5)
- # clj-kondo (6)
- # clojure (30)
- # clojure-europe (6)
- # clojure-japan (1)
- # clojure-nl (9)
- # core-logic (17)
- # data-oriented-programming (1)
- # datalevin (1)
- # datomic (2)
- # gratitude (2)
- # jobs (2)
- # kaocha (8)
- # lsp (1)
- # malli (8)
- # meander (8)
- # off-topic (18)
- # rdf (1)
- # re-frame (4)
- # reagent (16)
- # releases (1)
- # sci (1)
- # sql (1)
- # tools-deps (4)
- # xtdb (3)
related to is-a relations, malli should have more concrete type definitions in the core, e.g. pos-int?
is not a type, it’s a :int
with constraint of being positive. Less types to map in transformers and just better. Related:
• https://github.com/metosin/malli/issues/264
• https://github.com/clj-kondo/clj-kondo/blob/d9fca2705863e3e604e004ccb942e0b3d2e268ec/src/clj_kondo/impl/types.clj#L18-L51
on master - adding type-hints for providers, starting with :map-of
:
(require '[malli.provider :as mp])
(mp/provide
[^{::mp/hint :map-of}
{:a {:b 1, :c 2}
:b {:b 2, :c 1}
:c {:b 3}
:d nil}])
;[:map-of
; keyword?
; [:maybe [:map
; [:b int?]
; [:c {:optional true} int?]]]]
the current threshold with unified key & values schemas is 3, so:
(mp/provide
[{:a [1]
:b [1 2]
:c [1 2 3]}])
; [:map-of keyword? [:vector int?]]
with :malli.provider/tuple-threshold
defaulting to 3:
;; tuple-like with too few elements
[[:vector some?]
[[1 "2" true]
[2 "2" true]]]
;; tuple-like with enough samples
[[:tuple int? string? boolean?]
[[1 "2" true]
[2 "2" true]]
{::mp/tuple-threshold 2}]
;; tuple-like with enough samples
[[:tuple int? string? boolean?]
[[1 "2" true]
[2 "2" true]
[3 "3" true]]]
;; tuple-like with non-coherent data
[[:vector some?]
[[1 "2" true]
[2 "2" true]
[3 "3" "true"]]]
;; a homogenous hinted tuple
[[:tuple int? string? boolean?]
[^{::mp/hint :tuple} [1 "2" true]
[2 "2" true]]]
;; a hererogenous hinted tuple
[[:tuple int? string? some?]
[^{::mp/hint :tuple} [1 "2" true]
[2 "2" "true"]]]
;; invalid hinted tuple
[[:vector some?]
[^{::mp/hint :tuple} [1 "2" true]
[2 "2" true "invalid tuple"]]]