您当前的位置: 首页 >  kafka

段智华

暂无认证

  • 2浏览

    0关注

    1232博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

IMF Either 语义,kafkacluster获取分区使用(114)

段智华 发布时间:2016-07-24 12:58:48 ,浏览量:2

  IMF Either 语义,kafkacluster获取分区使用   def getPartitions(topics: Set[String]): Either[Err, Set[TopicAndPartition]] = {     getPartitionMetadata(topics).right.map { r =>       r.flatMap { tm: TopicMetadata =>         tm.partitionsMetadata.map { pm: PartitionMetadata =>           TopicAndPartition(tm.topic, pm.partitionId)         }       }     }   }       Either 语义

Either 也是一个容器类型,但不同于 Try、Option,它需要两个类型参数:Either[A, B] 要么包含一个类型为 A 的实例,要么包含一个类型为 B 的实例。 这和 Tuple2[A, B] 不一样, Tuple2[A, B] 是两者都要包含。

Either 只有两个子类型: Left、 Right, 如果 Either[A, B] 对象包含的是 A 的实例,那它就是 Left 实例,否则就是 Right 实例。

在语义上,Either 并没有指定哪个子类型代表错误,哪个代表成功,

关注
打赏
1659361485
查看更多评论
立即登录/注册

微信扫码登录

0.0519s