我们可以在RXJava中进行类似于其他功能语言的模式匹配吗?
谢谢, Sumanta
答案 0 :(得分:0)
我认为我们可以boolean java.lang.String.matches(String regex)
使用filter()
运算符;例如,假设我们需要计算PATTERN
列表中特定words
的匹配项数量,我们可以这样做:
private static final String PATTERN = "[q].*[A-Za-z]";
List<String> words = Arrays.asList("the","quick","brown","fox","jumped","over","the","lazy","dog");
Flowable.fromIterable(words)
.filter(elem->elem.matches(PATTERN))
.count()
.subscribe(System.out::println);
你得到:
1