Comments (4)
Hi Kasajian. Option<T>
and Lazy<T>
don't perform the same role. Lazy<T>
is deferred processing of a function until the value is required (if at all), and Option<T>
is a type that can represent a value or not a value (strictly, there's no laziness to it). A bit like a regular C# reference where it can be a value or be null
; however (unlike a null
reference) Option<T>
explicitly denies access to the contract of the generic parameter type of the Option, if there isn't a value inside.
There is a lazy Option type in the library, and that is TryOption<T>
, it's lazy out of necessity due to the fact that it needs to be a delegate so that it can catch any thrown exceptions. Take a look at TryMonadTests.cs
to see some examples.
Lazy<T>
is closer to 'memoization' in the functional world. Take a look at memo
function in Prelude_Memoize.cs
http://en.wikipedia.org/wiki/Memoization
from language-ext.
Thank you for the explanation.
And I agree with you that that's the purpose of the Lazy class, for momization. I was just saying that if put aside as to how the value get inside of Lazy or Option, they are similar in that:
- The are a container of a value.
- They work with both value types and objects.
- They may or may not contain a value.
- You can query it to determine if has a value.
Lazy doesn't create inner Value until you attempt to access it via the Value property. If you use the version of Lazy where you provide an initialization function, then you can simply access the Value property to force it to contain a value when one exists.
To illustrate, take a look a simple usage of it as an alternative to TryGetValue for Dictionary:
(my alias is zumalifeguard)
I can't disagree with you if your position is that using Lazy in this way is hackish and you may not want to rely on it for your framework. I was just curious if that, in fact, your stance.
from language-ext.
As I say the behaviour is different. Using a None
doesn't turn it into a Some
, that is what happens when you use a Lazy
. Option
types are in one state, and they stay in that state. Lazy
start in a 'valueless' state and then gain a value on usage.
from language-ext.
Thank you. You're right. When you have Option in your library, it's ideal. I was suggesting that without such library, if one wishes to return a value from a method that may be an object, null or no-value, then Lazy can be as an internal implementation that mimics Option. The client only sees a version of Lazy with a value or without a value. They don't use it to perform deferred instantiation. Anyway, I think I got the answer to my question. Thanks for your time.
from language-ext.
Related Issues (20)
- Can't cancel efffect HOT 13
- Missing some functions in OptionAsync HOT 1
- TryAsync prelude should have an overload that takes a Task HOT 1
- Creating a custom Either type with a custom fixed Left type. HOT 1
- Conflict between LangugeExt Extension methods and LINQ Extension methods HOT 2
- AffRxExtensions.Consume blocks the waiting thread on IObservable's completion
- How to make LanguageExt.CodeGen work on Unity? HOT 2
- Seq<EitherAsync<A, B>>.SequenceParallel does not preserve order HOT 11
- FileIO bug for Test when opening new file for writing
- Directory IO bug for Test when enumerating files
- Simple Kickstart Project available? CodeGen tool is outdated? dotnet8 HOT 1
- Implicit conversion of int? to Option<int> HOT 2
- SequenceParallel performance degradation in 4.4.8 HOT 1
- Refit.ApiException: 'An error occured deserializing the response.'
- Constructor not found for LanguageExt.LongRange HOT 1
- Alternative to inherit from Fin and other monads
- EitherAsync is missing HOT 4
- Add `DoAsync` to Either types (and maybe others) HOT 2
- Release build fails for a big application HOT 5
- v5 resource tracking issue? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from language-ext.