core.typed

annotation for mapv does not leverage non-empty collections

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

After hacking around CTYP-136, I tried this code:

(ann bar [(t/Coll t/AnyInteger) -> (U (Value :empty) t/AnyInteger)])
(defn bar [c]
  (if (seq c)
    (last (mapv inc c))
    :empty))

But got

Expected:       (U Long Integer BigInteger BigInt Byte Short (Value :empty))
Actual:         (U Long Integer BigInteger BigInt Byte Short (Value :empty) nil)

Re annotating as this worked around my problem:

(ann clojure.core/mapv
 (All [c a b ...]
    (Fn
     [[a b ... b -> c] (t/NonEmptySeqable a) (t/NonEmptySeqable b) ... b -> (t/NonEmptyVec c)]
     [[a b ... b -> c] (U nil (t/Seqable a)) (U nil (t/Seqable b)) ... b -> (clojure.lang.APersistentVector c)])))

Activity

Hide
Jake Goulding added a comment -

As discussed, I've added AVec and NonEmptyAVec and then used that instead.

Show
Jake Goulding added a comment - As discussed, I've added AVec and NonEmptyAVec and then used that instead.
Hide
Ambrose Bonnaire-Sergeant added a comment -

Thanks! Merged.

Show
Ambrose Bonnaire-Sergeant added a comment - Thanks! Merged.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: