简体   繁体   English

dartz 中的 any 和 Option 有什么区别?

[英]what is the difference between either and Option in dartz?

i am trying to understand dartz, but the documentation is not clear enough.我想了解 dartz,但文档不够清楚。 i need to get the difference between either and Option in dartz?我需要在 dartz 中找出两者之间的区别吗?

abstract class Option<A> implements TraversableMonadPlusOps<Option, A>

VS VS

abstract class Either<L, R> implements TraversableMonadOps<Either<L, dynamic>, R> 

Well, an Option type normally is a type that holds either a typed value, or nothing.嗯,一个Option类型通常是一个保存类型值或什么都不保存的类型。

For example if you want to get the first integer of a list of integers, that might be an Option<int> because it can be an int or nothing in case the list is empty.例如,如果您想获取整数列表的第一个 integer,那可能是Option<int>因为如果列表为空,它可以是 int 或什么都没有。 But it cannot be a string.但它不能是字符串。

An Either type is just what the name says... either one or the other. Either类型就是名字所说的......要么是一个,要么是另一个。 And it can be two different types altogether.它可以完全是两种不同的类型。 Either<int, string> would have either an int or a string. Either<int, string>将有一个 int一个字符串。 Never both.从不两者兼而有之。 Never none.从来没有。 Either one or the other.要么之一。

For example a functional ParseInt method might return a Either<int, string> , because it will return either a valid int, or an error message.例如,功能性 ParseInt 方法可能会返回Either<int, string> ,因为它将返回有效的 int 或错误消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM