purescript-contrib / purescript-profunctor-lenses

Pure profunctor lenses
MIT License
144 stars 52 forks source link

Should prism and lens be defined as #57

Open phadej opened 7 years ago

phadej commented 7 years ago
prism :: (b -> t) -> (s -> Either t a) -> Prism s t a b
prism setter getter pab = dimap getter (either id setter) (right pab)

Then there won't be unnecessary rmap preprocessing.

lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens getter setter pab = dimap (\s -> (getter s, s)) (\(b, s) -> setter s b) (first' pab)

and here we won't apply setter to s before actually needed (making of pair is unavoidable)

paf31 commented 7 years ago

That sounds like an improvement to me.