public static IModelObservable <T> Take <T>(this IModelObservable <T> source, int number) { return(Create <T>( o => { int count = 0; IDisposable disposable = null; disposable = source.Observe( i => { count++; if (count <= number) { o.OnNext(i); } else { disposable.Dispose(); } }, o.OnCompleted ); return disposable; } )); }
public void Update(IModelObservable observable) { ResetLattices(); if (player1 != null) { foreach (Object o in player1.Chesses) { Chess c = o as Chess; if (c.state == ChessState.ALIVE) { chessBoardHash[c.posId / CHESS_BOARD_SIZE, c.posId % CHESS_BOARD_SIZE] = ChessOwner.PLAYER1; SetButtonStyle(chessBoardLattices[c.posId / CHESS_BOARD_SIZE, c.posId % CHESS_BOARD_SIZE], c); } } } if (player2 != null) { foreach (Object o in player2.Chesses) { Chess c = o as Chess; if (c.state == ChessState.ALIVE) { chessBoardHash[c.posId / CHESS_BOARD_SIZE, c.posId % CHESS_BOARD_SIZE] = ChessOwner.PLAYER2; SetButtonStyle(chessBoardLattices[c.posId / CHESS_BOARD_SIZE, c.posId % CHESS_BOARD_SIZE], c); } } } }
public static IModelObservable <TSubModel> Select <TModel, TSubModel>(this IModelObservable <TModel> source, Func <TModel, TSubModel> selector) { return(Create <TSubModel>( o => { var disposable = source.Observe( i => { o.OnNext(selector(i)); }, o.OnCompleted ); return disposable; } )); }
public static IModelObservable <T> Where <T>(this IModelObservable <T> source, Func <T, bool> predicate) { return(Create <T>( o => { var disposable = source.Observe( i => { if (predicate(i)) { o.OnNext(i); } }, o.OnCompleted ); return disposable; } )); }