Skip to content
Ambrose Bonnaire-Sergeant edited this page Nov 15, 2015 · 5 revisions

Limitations

Using filter

Not everything can be inferred from a filter. A common example is (filter identity coll) does not work. The reason is identity only gives negative information when its result is true: that the argument is not (U nil false).

This idiom must be converted to this syntax (fn [a] a) and then annotated with positive propositions.

;eg. 

(filter (ann-form (fn [a] a)
                  [(U nil Number) -> (U nil Number) :filters {:then (is Number 0)}])
        [1 nil 2])
; :- (Seqable Number)

Positive information infers just fine, like (filter number? coll). The above idiom is useful when you are filtering something like a (Seqable (U nil x)) and there is no predicate to test for x, so you can only test if something isn't nil.

Clone this wiki locally