Mono Map vs Flatmap

本文深入探讨了Project Reactor中Mono.flatMap与Mono.map的使用场景与差异。Mono.flatMap接收一个将值转换为另一个Mono的函数,适用于异步处理如HTTP请求;而Mono.map接收一个将类型T的值转换为类型R的值的函数,转换过程同步进行,例如将字符串转换为URL实例。此外,flatMap会订阅生成的Mono,这是与map操作符的主要区别。

https://stackoverflow.com/questions/56496426/project-reactor-mono-map-vs-mono-flatmap

Mono#flatMap takes a Function that transforms a value into another Mono. That Mono could represent some asynchronous processing, like an HTTP request.

On the other hand, Mono#map takes a Function that transforms a value of type T into another value, of type R. That transformation is thus done imperatively and synchronously (eg. transforming a String into an URL instance).

The other subtlety with flatMap is that the operator subscribes to the generated Mono, unlike what would happen if you passed the same Function to map.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值