Closed justanr closed 9 years ago
Hm. Perhaps implementing this is something better left to end users. The framework is already in place: inheriting from pynads.Monoid
and the pynads.funcs.monoids
module. Rather than attempting to cover this base, I'm simply closing the issue as it's non-critical. Perhaps I'll revisit it in the future.
The current implementation of
First
,Last
,Sum
,Product
andEndo
(here) strikes me partially as a clean implementation of these and partially as "what the hell are these things that are a bag of staticmethods?"For example,
First
can be completely replaced by a function:And since
Last
can be defined in terms ofFirst
:However, Haskell actually implements these as full wrappers around Maybe:
Similarly:
To pull the Maybe out of First or Last, the selector function is used:
getLastJust
can similarly defined.Implementing this with Pynads is pretty much free as Monoid inherits from Container, which implements
Container.v
for us, so it can be done like this:Use then changes to this:
Which is more inline with Haskell's implementation. Similarly, Endo, Sum and Product can be redefined to follow this.