zoran-horvat / optional Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I've already got an Option struct I implemented but I've been looking at yours to see if I could learn anything about good coding practice. It seems to me that the == operator won't work as expected if you've got two Option instances because the == operator is not defined on the abstract base class. The == operator is defined on Some and None but most of the time you'll have variables passed around as type Option so that seems to be the key scenario to support. I think you can do safe equality comparisons on the base class by comparing types (None!=Some) AND the Reduce value. Override the equality and inequality operators, and do IEquatable too. Then, to support IEquatable<Some> and IEquatable<None> in the derived classes, just have a single line like public bool Equals(Some<T> other) => (this as Option<T>).Equals(other as Option<T>);
At first I liked your approach of using an abstract base class to support both Some and None but given the value equality issues I wonder if a cleaner solution is just to use a single class for both.
I'm not sure all the code is included here. In your tests you reference IOption but I can't see that interface anywhere. Also when I download the whole repository into Visual Studio the test project isn't included automatically. I'm not that familiar with Git so maybe I'm doing it wrong. By the way, I love your Pluralsight presentations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.