Recommended
C#を始めたばかりの人へのLINQ to Objects
LINQ 概要 + 結構便利な LINQ to XML
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
最新C#動向と関数型言語haskell ~命令型静的プログラミングから関数型動的プログラミングへのシフト~
Visual Studio による開発環境・プログラミングの進化
Unity2015_No10_~UGUI&Audio~
TypeScript & 関数型講座 第3回 関数型入門
「再代入なんて、あるわけない」 ~ふつうのプログラマが関数型言語を知るべき理由~ (Gunma.web #5 2011/05/14)
More Related Content
C#を始めたばかりの人へのLINQ to Objects
LINQ 概要 + 結構便利な LINQ to XML
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
Similar to Rx class (20)
最新C#動向と関数型言語haskell ~命令型静的プログラミングから関数型動的プログラミングへのシフト~
Visual Studio による開発環境・プログラミングの進化
Unity2015_No10_~UGUI&Audio~
TypeScript & 関数型講座 第3回 関数型入門
「再代入なんて、あるわけない」 ~ふつうのプログラマが関数型言語を知るべき理由~ (Gunma.web #5 2011/05/14)
Rx class3. 三項演算子とは
int score = 50;
string result = "";
if(score > 80)
{
result = "合格";
}
else
{
result = "不合格";
}
int score = 50;
string result = "";
result = (score > 80) ? "合格" : "不合格";
8. SQLの例
SELECT 価格 FROM 商品表 WHERE 価格 < 300 ORDER BY ASC
商品表 価格
価格 <
300
価格 <
300
昇順並び替え
複数の式を結合し、データの塊を最終的な形になるまで操作する。
9. LINQとは
C#でSQLクエリっぽい
書き方ができる
class Product
{
public string name;
public int price;
public Product(string n, int p)
{
name = n;
price = p;
}
}
// Use this for initialization
void Start () {
List<Product> productList = new List<Product>();
productList.Add(new Product("リンゴ", 120));
productList.Add(new Product("みかん", 80));
productList.Add(new Product("お米", 900));
productList.Select(x => x.price)
.Where(x => x < 300)
.OrderBy(x => x);
}
14. LINQとは
集約関数も使える
productList.Where(x => x.price < 300).Count(); //2
productList.Select(x => x.price).Sum(); //1100
productList.Select(x => x.price).Average(); //367
productList.Select(x => x.price).Max(); //900
productList.Select(x => x.price).Min(); //80
25. UNIRXを使ってみよう
public class RxObserver : MonoBehaviour {
[SerializeField]RxTest _rxTest;
// Use this for initialization
void Start () {
_rxTest.OnHpChanged.Subscribe(x =>
{
Debug.Log("Hp change : " + x);
});
}
}
public class RxTest : MonoBehaviour {
Subject<int> _hpNotify = new Subject<int>();
public IObservable<int> OnHpChanged {
get
{
return _hpNotify;
}
}
private void Start()
{
int hp = 100;
_hpNotify.OnNext(hp);
hp = 50;
_hpNotify.OnNext(hp);
}
}
イベント購読側
イベント発行側
29. UNIRXを使ってみよう
public class RxTest : MonoBehaviour {
ReactiveProperty<int> HP = new ReactiveProperty<int>();
private void Start()
{
HP.Value = 100;
HP.Value = 50;
}
}
イベント発行側
値の変更をするだけで、OnNextと同等の動作を行う