LoginSignup
0
0

More than 5 years have passed since last update.

RealmFlowソースコード覚書

Last updated at Posted at 2018-02-17

自分用メモです。

struct RealmFlow の型引数

struct RealmFlow<RW : ReadWriteType, T, U, ROW: RawOrWrap>

RW

幽霊型その1

現在必要とされているトランザクションの種類が
- ReadOnly
- WriteOnly
- ReadWrite
なのかを覚えておくための幽霊型。

これにより、realm.run(flow: flow) が呼ばれた時に、realm.beginWriteTransaction()を呼び出す必要があるかどうかをコンパイル時に決定出来る。

参考: Realmの処理を再利用可能かつ合成可能にする@社内iOS勉強会

T

入力の型。

たいていは、Realm.Objectの子クラスのはず。

U

出力の型。

subscribe() に渡される引数の型と考えれば、ほぼ間違いない。

ROW

幽霊型その2

Uが、 生データRaw( Realm.Results<T> ) なのか ラップされたデータWrap( SequenceWrapper<T> ) なのかを表す。

抽象class SequenceWrapper

class SequenceWrapper<T> は以下のシグネチャを持つ。

var first: T?

var count: Int

func max(by: (T, T) throws -> Bool) rethrows -> T?

func min(by: (T, T) throws -> Bool) rethrows -> T?

func prefix(_ maxLength: Int) -> AnySequence<T>

func suffix(_ maxLength: Int) -> AnySequence<T>

func forEach(_ body: (T) throws -> Void) rethrows

func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, T) throws -> Result) rethrows -> Result

func reduce<Result>(into initialResult: Result, _ updateAccumulatingResult: (inout Result, T) throws -> ()) rethrows -> Result

func makeIterator() -> SequenceWrapper<T>._Iterator

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0