From操作符的作用

从指定数据数据源获取数据并创建一个Observable,数据源分如下几类:

  • 现有的数据
  • 异步获取的数据
  • 数据流

image.png

示例代码

RxJava版本:2.2.19

  • fromArray(T... items)
  • fromIterable(Iterable<? extends T> source)<br />
  • fromCallable(Callable<? extend T> supplier)
  • fromFuture(Future<? extends T> future)
  • fromFuture(Future<? extends T> future, long timeout, TimeUnit unit)
  • fromFuture(Future<? extends T> future, long timeout, TimeUnit unit, Scheduler scheduler)
  • fromFuture(Future<? extends T> future, Scheduler scheduler)
  • fromPublisher(Publisher<? extends T> publisher)

    FromArray和FromIterable

    参考最上面的弹珠图(marble diagrams) ```java String[] names = {“Lucy”, “Andy”, “John”, “Lee”}; Observable fromArray = Observable.fromArray(names);

List nameList = Arrays.asList(names); Observable fromIterable = Observable.fromIterable(nameList);

  1. <a name="3zVgc"></a>
  2. ### FromFuture
  3. **![image.png](https://cdn.nlark.com/yuque/0/2020/png/879708/1588821607319-8691ee80-430d-427e-8a01-59fb9b89cdac.png#align=left&display=inline&height=295&margin=%5Bobject%20Object%5D&name=image.png&originHeight=630&originWidth=1280&size=80760&status=done&style=none&width=600)<br />**
  4. ```java
  5. //TBD

FromPublish

//TBD

参考资料

http://reactivex.io/documentation/operators/from.html