1. The document discusses RESTful APIs and gRPC, comparing their characteristics and use cases.
2. RESTful APIs typically use HTTP and JSON to access resources via URLs while gRPC uses protocol buffers and HTTP/2 for efficient streaming and RPC.
3. gRPC is better suited for microservices and mobile apps due to its ability to handle streaming and performance, while REST is more widely used due to its simplicity and support in most languages.
ブログでもいろいろ解説しています。
http://little-hands.hatenablog.com/entry/top
ドメイン駆動設計屈指の難解な概念「境界付けられたコンテキスト」について解説します。
---
公式DDD Referenceの定義は以下の通りです。(和訳はだいぶ意訳しています)
bounded context
A description of a boundary (typically a subsystem, or the work of a particular team) within which a particular model is defined and applicable.
境界付けられたコンテキスト
特定のモデルを定義・適用する境界を明示的に示したもの。
代表的な境界の例は、サブシステムやチームなど。
まぁなかなかよくわからないですよね。DDD用語の中でもかなり難解なワードです。 境界付けられたコンテキストは、2つの観点から解説が必要でしょう。
・概念としての境界付けられたコンテキスト
・境界付けられたコンテキストをどう実装に落としこむか
今回のスライドでは、概念の方の説明をしたいと思います。
1. The document discusses RESTful APIs and gRPC, comparing their characteristics and use cases.
2. RESTful APIs typically use HTTP and JSON to access resources via URLs while gRPC uses protocol buffers and HTTP/2 for efficient streaming and RPC.
3. gRPC is better suited for microservices and mobile apps due to its ability to handle streaming and performance, while REST is more widely used due to its simplicity and support in most languages.
ブログでもいろいろ解説しています。
http://little-hands.hatenablog.com/entry/top
ドメイン駆動設計屈指の難解な概念「境界付けられたコンテキスト」について解説します。
---
公式DDD Referenceの定義は以下の通りです。(和訳はだいぶ意訳しています)
bounded context
A description of a boundary (typically a subsystem, or the work of a particular team) within which a particular model is defined and applicable.
境界付けられたコンテキスト
特定のモデルを定義・適用する境界を明示的に示したもの。
代表的な境界の例は、サブシステムやチームなど。
まぁなかなかよくわからないですよね。DDD用語の中でもかなり難解なワードです。 境界付けられたコンテキストは、2つの観点から解説が必要でしょう。
・概念としての境界付けられたコンテキスト
・境界付けられたコンテキストをどう実装に落としこむか
今回のスライドでは、概念の方の説明をしたいと思います。
13. get/set Lens
class Lens[S, A](
getter: S => A,
setter: S => A => S
) {
def get(s: S): A = getter(s)
def set(s: S, a: A): S = setter(s)(a)
def modify(s: S, f: A => A): S = set(s, f(get(s)))
}
19. Lens の合成を考える
class Lens[S, A](getter: S => A, setter: S => A => S) {
def get(s: S): A = getter(s)
def set(s: S, a: A): S = setter(s)(a)
def modify(s: S, f: A => A): S = set(s, f(get(s)))
def ^|->[B](other: Lens[A, B]): Lens[S, B] = new Lens(
s => other.get(this.get(s)), // getter
s => b => this.set(s, other.set(this.get(s), b)) //setter
)
}
20. Lens の合成を考える
def ^|->[B](other: Lens[A, B]): Lens[S, B] = new Lens(
s => other.get(this.get(s)), // getter
s => b => this.set(s, other.set(this.get(s), b)) //setter
)
21. 試してみよう
case class Message(user: User, body: String)
// Message#id 対 Lens
val _body = ...
// Message#user 対 Lens
val _user: Lens[Message, User] = new Lens(
_.user,
message => newUser => message.copy(user = newUser)
)
22. Before
val message = Message(User(100, "John Doe"), "Hello")
message.user // res: User = User(100,John Doe)
message.user.name // res: String = John Doe
message.copy(
user = user.copy(
name = "aoino"
)
) // res: Message = Message(User(100,aoino), Hello)
message.copy(
user = user.copy(
name = message.user.name.toUpperCase
)
) // res: Message = Message(User(100,JOHN DOE),Hello)
23. A er
val message = Message(User(100, "John Doe"), "Hello")
_user.get(message)
// res: User = User(100,John Doe)
(_user ^|-> _name).get(message)
// res: String = John Doe
(_user ^|-> _name).set(message, "aoino")
// res: Message = Message(User(100,aoino),Hello)
(_user ^|-> _name).modify(message, _.toUpperCase)
// res: Message = Message(User(100,JOHN DOE),Hello)
26. A == Option[B] となるようなLens を考えてみる。
class Lens[S, A](
getter: S => A,
setter: S => A => S
) {
// ...
}
27. すると、A がOption[B] となるような場合に
get メソッドが実装出来ない。
class BadLens[S, B](
getter: S => B,
setter: S => B => S
) {
def get(s: S): B = getter(s) match {
case Some(b) => b
case None => ??? /// 何 返
}
/// ...
}
60. setter の再考
冒頭に出てきたsetter の型は以下の通り。
def setter: S => A => S
これはmodify メソッドの特殊形と考えられる。
なので、modify のsignature を取り入れて
def setter: S => (A => A) => S
と、改めて定義する。
82. f にId/Const が入ります。 構造のネストする順番と合成
の順序が一致し、左から右へと辿れますね。
traverse
:: (Applicative f, Traversable t) =>
(a -> f b) -> t a -> f (t b)
traverse . traverse
:: (Applicative f, Traversable t, Traversable t1) =>
(a -> f b) -> t (t1 a) -> f (t (t1 b))
traverse . traverse . traverse
:: (Applicative f, Traversable t, Traversable t1, Traversable t2) =>
(a -> f b) -> t (t1 (t2 a)) -> f (t (t1 (t2 b)))
おやおや?このHaskell の関数合成に使う(.) 演算子が、
Scala やJava などの(.) 演算子に見えませんか?