@Test public void testMap() { LiveData<String> source = new MutableLiveData<>(); LiveData<Integer> mapped = Transformations.map(source, new Function<String, Integer>() { @Override public Integer apply(String input) { return input.length(); } }); Observer<Integer> observer = mock(Observer.class); mapped.observe(mOwner, observer); source.setValue("four"); verify(observer).onChanged(4); }
@MainThread public static <X, Y> LiveData<Y> map(LiveData<X> source, final Function<X, Y> func) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(func.apply(x)); } }); return result; }
Transformations { @MainThread public static <X, Y> LiveData<Y> map(LiveData<X> source, final Function<X, Y> func) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(func.apply(x)); } }); return result; } }
Transformations { @MainThread public static <X, Y> LiveData<Y> map(LiveData<X> source, final Function<X, Y> func) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(func.apply(x)); } }); return result; } private  Transformations(); }
Transformations { @MainThread public static <X, Y> LiveData<Y> map(LiveData<X> source, final Function<X, Y> func) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(func.apply(x)); } }); return result; } private  Transformations(); @MainThread static LiveData<Y> map(LiveData<X> source, final Function<X, Y> func); @MainThread static LiveData<Y> switchMap(LiveData<X> trigger,
            final Function<X, LiveData<Y>> func); }
Transformations { @MainThread public static <X, Y> LiveData<Y> map(LiveData<X> source, final Function<X, Y> func) { final MediatorLiveData<Y> result = new MediatorLiveData<>(); result.addSource(source, new Observer<X>() { @Override public void onChanged(@Nullable X x) { result.setValue(func.apply(x)); } }); return result; } private  Transformations(); @MainThread static LiveData<Y> map(LiveData<X> source, final Function<X, Y> func); @MainThread static LiveData<Y> switchMap(LiveData<X> trigger,
            final Function<X, LiveData<Y>> func);  }