ekmett / kan-extensions

Kan extensions, Kan lifts, the Yoneda lemma, and (co)monads generated by a functor
Other
79 stars 33 forks source link

Some Foldable methods for Coyoneda can respect underlying structure more #23

Open treeowl opened 8 years ago

treeowl commented 8 years ago

In particular:

  foldr c n (Coyoneda k a) = foldr (c . k) n a 
  foldl f b (Coyoneda k a) = foldl (\acc -> f acc . k) go b a
  -- foldl', foldr', foldl1, foldr1 similarly
  toList (Coyoneda k a) = map k (toList a) -- but this is arguably worse than the default!
  length (Coyoneda _ a) = length a
  null (Coyoneda _ a) = null a

Unfortunately, I don't believe it's possible to do anything about fold, maximum, minimum, sum, product, or elem.