返回布尔值可观察到的管道运算符

时间:2018-12-01 23:16:21

标签: typescript rxjs

我正在尝试实现一个返回布尔值可观察值的方法,如果另一个可观察值包含真实值,则该值为true。这是大多数实现:

   /**
     * Observe changes to the values.
     * 
     * @param key 
     * @return An {@link Observable<boolean>} indicating whether the value exists.
     */
    public exists(key:string) {
        if (!this.subjects[key]) {
            throw new Error(`No subject exists for the key ${key}`);
        }
        return this.subjects[key].asObservable().pipe(???);
    }

是否存在执行value != null检查的操作员?像isDefined运算符一样?

1 个答案:

答案 0 :(得分:1)

map(value => !!value)

没有运算符可以将某些值转换为布尔值。