Language-Ext 5.0 alpha-2 #1309
louthy
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
General updates
Freemonad doesn't needAlternativetrait: removedAppendoperator renamed toCombine. 'Combine' works semantically for more of the monoidal associative operations thanAppend(which really only makes sense with collections).SemigroupKandMonoidK-- these are like theSemigroupandMonoidtraits except they work onK<M, A>instead ofA. These are almost identical toSemiAlternativeandAlternativeexecept they don't require the underlying value to an anApplicative. The idea here is thatSemigroupKandMonoidKwould be used on types like collections that 'sum' when theCombineoperator is applied, whereasSemiAlternativeandAlternativeprovide an alternative value when theCombineoperator is applied (coalescing).repeatvariants,retryvariants, andtimeoutfor the IO monadIO.yieldFor(TimeSpan). This is likeTask.Delaybut for the IO monad. The war against async means that this does the thread-yielding internally, no need to call await. I figuredyieldForis more meaningful thanDelay, it indicates that the thread is yielding, not simply blocking.ContT<R, M, A>-- just the raw type for now.HeadOrNone,HeadOrInvalid,HeadOrLeft,LastOrNone, etc. have been removed.HeadandLastare nowOptionreturning. This is a breaking change. Can be mitigated by either matching, casting, or invocation of.ValueUnsafe()extension.Rangetype -- previously there were several types (IntegerRange,CharRange, etc.) -- now there's just one:Range<A>. It leverages the new traits built into .NET (IComparisonOperators,IAddtionOperators, etc.)Foldable.Sum,Foldable.Max, etc.: (IComparisonOperators,IAddtionOperators,IAdditiveIdentityetc.) -- these are Microsoft's ugly named versions of monoids etc.War on Extension Methods
I'm rapidly coming to the conclusion that extension-methods are a terrible idea. Especially in a library like language-ext where I am trying to present a consistent set of interfaces to types that share common traits. It's just impossible to enforce consistency and relies on the human eye -- and that errs regularly!
The latest move toward using traits is really starting to help reduce the extension methods, or at least mean the extension methods are hanging off traits rather than individual instance-types.
One change that I have made recently is to change
Foldableto require implementation ofFoldWhileandFoldWhileBackinstead ofFoldandFoldBack. This means that so many more default behaviours can hang off ofFoldable-- and most of them are optimal. For example,Exists-- which can stop processing as soon as its predicate returnstrue-- couldn't early-out before.And so, the foldable trait is now growing to have a ton of functionality. Also nested foldables!
However, quite a lot of those methods, like
Sum,Count, etc. also exist onIEnumerable. And so, for a type likeSeqwhich derives from bothIEnumerableandK<Seq, A>, there will be extension method resolution issues.So, the choice is to provide extension methods for
IEnumerable(an ill defined type) or forFoldable- a super featureful type with the opportunity for implementers to provide bespoke optimised overrides.Really, the choice should be easy: extensions for Foldable are just better than extensions for
IEnumerable. So, I have done that. The downside is that this will be another breaking change (because theIEnumerableextensions have been removed). The fix is to convert fromIEnumerable<A>toEnumerableM<A>using.AsEnumerableM().EnumerableM<A>supportsFoldable(and other traits).Conclusion
So, I've been working to remove as many non-trait extension methods as I can -- and I will continue to do so leading up to the beta. This will bring consistency to the code-base, reduce the amount of code, and provide ample opportunities for bespoke optimisations. Just be aware that this is another fix-up job.
This discussion was created from the release Language-Ext 5.0 alpha-2.
Beta Was this translation helpful? Give feedback.
All reactions