Result of first observable (itemsCache.GetAllKeys()) is list of strings. If that list contains certain string (DOKUMENTI_KEY), then second observable should be caled. If first observable doesent contain certain string (DOKUMENTI_KEY), then empty list should be returned.
public static IObservable<TResult> If<TSource, TResult>(
this IObservable<TSource> source,
Func<TSource, bool> predicate,
Func<TSource, IObservable<TResult>> thenSource,
Func<TSource, IObservable<TResult>> elseSource)
{
return source
.SelectMany(
value => predicate(value)
? thenSource(value)
: elseSource(value));
}
public IObservable<List<Dokument>> GetDokumenti()
{
return Observable.If(
() => itemsCache.GetAllKeys().SelectMany(x => x).Contains(DOKUMENTI_KEY).GetAwaiter().GetResult(),
itemsCache.GetAllKeys().SelectMany(y => y).SelectMany(z => itemsCache.GetObject<List<Dokument>>(z)),
Observable.Return(new List<Dokument>())
);
}
Is there a better way to do this?
Aucun commentaire:
Enregistrer un commentaire