Skip to content

Add Flow#collectNonNull operator #2178

@He-Pin

Description

@He-Pin

This operator is been used in Spring ai, and I think it's actually useful than a map to Optional/Option and a then filter/collect

			return doGetObservableFluxChatResponse(this.request)
					.mapNotNull(ChatClientResponse::chatResponse)
					.map(r -> Optional.ofNullable(r.getResult())
							.map(Generation::getOutput)
							.map(AbstractMessage::getText)
							.orElse(""))
					.filter(StringUtils::hasLength);

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions