{"id":343632,"date":"2023-01-08T03:00:34","date_gmt":"2023-01-08T03:00:34","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343632"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343632","title":{"rendered":"<span>Go: \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u044b \u0438 \u0442\u0438\u043f\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0414\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443 \u0442\u0435\u0445, \u043a\u0442\u043e \u043f\u0438\u0448\u0435\u0442 \u043d\u0430 Go \u0431\u044b\u043b\u043e \u0434\u0432\u0430 \u043f\u0443\u0442\u0438: \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0430 \u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f. \u0424\u0430\u043d\u0430\u0442\u043e\u043c \u043d\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e, \u043d\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043a \u043c\u043e\u0435\u0439 \u0440\u0430\u0434\u043e\u0441\u0442\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0438 \u0432 Go \u0435\u0441\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430! \u041d\u043e \u043d\u0435 \u0442\u0443\u0442-\u0442\u043e \u0431\u044b\u043b\u043e, \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 Go \u0438\u043c\u0435\u044e\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, <em>\u043f\u043e\u0440\u0442\u044f\u0442 \u0432\u0441\u044e \u043c\u0430\u043b\u0438\u043d\u0443<\/em>. \u0421 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043d\u0435 \u0438 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/h2>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041d\u0438\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f &#171;\u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 Go, \u0438 \u043a\u0430\u043a \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c&#187;, \u0437\u0430 \u0441\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u0433\u0434\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0436\u0435\u0432\u0430\u043d\u043e.<\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D1%82%D1%80%D0%BE%D0%B8%D1%82%D0%B5%D0%BB%D1%8C_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)\" rel=\"noopener noreferrer nofollow\"><em>\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c (builder)<\/em><\/a> \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043c\u0435\u0442\u044c \u043b\u0438\u0448\u044c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c, \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c, \u0434\u0435\u043b\u0438\u0442\u044c, \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"go\">type Calc struct { value float64 }  func NewCalc(value float64) Calc { return Calc{value: value} }  func (c Calc) Add(operand float64) Calc { return Calc{value: c.value + operand} }  func (c Calc) Sub(operand float64) Calc { return Calc{value: c.value - operand} }  func (c Calc) Mul(operand float64) Calc { return Calc{value: c.value * operand} }  func (c Calc) Div(operand float64) Calc { return Calc{value: c.value \/ operand} }  func (c Calc) Value() float64 { return c.value }<\/code><\/pre>\n<p>\u041f\u0443\u0441\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u044f\u0434\u0440\u043e\u043c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<pre><code class=\"go\">calc := NewCalc(0)  a := calc.Add(6).Mul(3).Div(2).Sub(1).Value() \/\/ 8 b := calc.Sub(10).Div(2).Add(6).Value() \/\/ 1  fmt.Printf(\"a + b = %f\\n\", calc.Add(a).Add(b).Value()) \/\/ a + b = 9<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Calc<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439, \u0430 \u043c\u044b \u043b\u0438\u0448\u044c \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u043e\u0442\u043a\u0443\u0434\u0430-\u0442\u043e \u0438\u0437\u0432\u043d\u0435.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0439 \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c \u043a\u043e\u0434 \u044f\u0434\u0440\u0430 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434, \u0447\u0435\u043c \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443.<\/p>\n<pre><code class=\"go\">type CommandName uint8  \/\/ \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430. const ( CommandNameAdd CommandName = iota CommandNameSub CommandNameMul CommandNameDiv )  \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0438\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043e\u043f\u0435\u0440\u0430\u043d\u0434. type Command struct { Name    CommandName Operand Calc }  \/\/ \u041f\u0430\u043a\u0435\u0442\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 func ProcessCommands(calc Calc, commands ...Command) Calc { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c, \u0438\u043c\u0435\u044f \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 <code>Calc<\/code> \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0432\u0438\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code>, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0438\u0437\u0432\u043d\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c:<\/p>\n<pre><code class=\"go\">calc := NewCalc(0)  \/\/ \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 a \u0438 b \u0445\u0440\u0430\u043d\u0438\u043c \u0443\u0436\u0435 \u043d\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 a := ProcessCommands(calc, Command{CommandNameAdd, NewCalc(6)}, Command{CommandNameMul, NewCalc(3)}, Command{CommandNameDiv, NewCalc(2)}, Command{CommandNameSub, NewCalc(1)}, )  b := ProcessCommands(calc, Command{CommandNameSub, NewCalc(10)}, Command{CommandNameDiv, NewCalc(2)}, Command{CommandNameAdd, NewCalc(6)}, )  \/\/ \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 (`a`) \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u044b sum := ProcessCommands(a, Command{CommandNameAdd, b}).Value() fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9<\/code><\/pre>\n<p>\u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0442\u0430\u043a \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u0437\u0430\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u043e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0438\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437:<\/p>\n<pre><code class=\"go\">\/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 A initA := []Command{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 B initB := []Command{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 calc := NewCalc(0)  a := ProcessCommands(calc, initA...) b := ProcessCommands(calc, initB...) sum := ProcessCommands(a, Command{CommandNameAdd, b}).Value()  fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c, \u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 (<em>M+<\/em>, <em>M-<\/em>, <em>MC<\/em>) \u0431\u0435\u0437 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u044f\u0434\u0440\u0430, \u0447\u0442\u043e, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0435\u043c\u044b.<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f: \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0438\u0445 \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438 \u0431\u0435\u0437\u0443\u043c\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435&#8230; \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0435 \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435 \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435? \u041d\u0430\u0431\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u0443\u0441\u043a\u0430\u0439, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0438\u043f\u0430 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0437\u0430 \u0431\u043e\u0440\u0442. \u0421\u043a\u0430\u0437\u0430\u043d\u043e &#8212; \u0441\u0434\u0435\u043b\u0430\u043d\u043e:<\/p>\n<pre><code class=\"go\">type Vector struct { X float64 Y float64 Z float64 }  type VectorCalc struct { value Vector }  func NewVectorCalc(value Vector) VectorCalc { return VectorCalc{value: value} }  func (c VectorCalc) Add(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.X + operand.X, Y: c.value.Y + operand.Y, Z: c.value.Z + operand.Z, }, } }  func (c VectorCalc) Sub(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.X - operand.X, Y: c.value.Y - operand.Y, Z: c.value.Z - operand.Z, }, } }  func (c VectorCalc) Mul(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.Y*operand.Z - c.value.Z*operand.Y, Y: -(c.value.Z*operand.X - c.value.X*operand.Z), Z: c.value.X*operand.Y - c.value.Y*operand.X, }, } }  func (c VectorCalc) Div(operand Vector) VectorCalc { \/\/ \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 panic(\"operation is not defined\") }  func (c VectorCalc) Value() Vector { return c.value }<\/code><\/pre>\n<p>\u041d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043e\u0431\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"go\">type Calculator[T any, V any] interface { Add(operand V) T Sub(operand V) T Mul(operand V) T Div(operand V) T Value() V }<\/code><\/pre>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0438\u043f\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"go\">type Command[T any, V any] struct { Name    CommandName Operand Calculator[T, V] }  func ProcessCommands[T any, V any](calc Calculator[T, V], commands ...Command[T, V]) Calculator[T, V] { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0443\u0440\u043e\u0432\u0430\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u044c\u0435\u0442 \u043f\u043e \u0433\u043e\u043b\u043e\u0432\u0435, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>T<\/code> \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code>. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u0432\u0435\u0434\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e <code>T<\/code> &#8212; \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>ProcessCommands<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>calc<\/code>, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 &#8212; \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>T<\/code> \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e <code>T<\/code> &#8212; \u044d\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f (<code>any<\/code>), \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0438\u043a\u0430\u043a \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e <code>T<\/code> \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u0442\u0438\u043f, \u0447\u0442\u043e \u0438 <code>Calculator[T, V]<\/code>.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 1<\/h2>\n<p>\u0427\u0442\u043e \u0436, \u043d\u0435 \u0431\u0435\u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"go\">func ProcessCommands[T Calculator[T, V], V any](calc Calculator[T, V], commands ...Command[T, V]) Calculator[T, V] { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u044f\u0434\u0440\u043e\u043c:<\/p>\n<pre><code class=\"go\">initA := []Command[Calc, float64]{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  initB := []Command[Calc, float64]{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  calc := NewCalc(0)  a := ProcessCommands[Calc, float64](calc, initA...) b := ProcessCommands[Calc, float64](calc, initB...) sum := ProcessCommands(a, Command[Calc, float64]{CommandNameAdd, b}).Value()  fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9  initVectorA := []Command[VectorCalc, Vector]{ {CommandNameAdd, NewVectorCalc(Vector{1, 1, 1})}, {CommandNameMul, NewVectorCalc(Vector{2, -2, 2})}, }  initVectorB := []Command[VectorCalc, Vector]{ {CommandNameSub, NewVectorCalc(Vector{10, 10, 10})}, }  vcalc := NewVectorCalc(Vector{})  va := ProcessCommands[VectorCalc, Vector](vcalc, initVectorA...) vb := ProcessCommands[VectorCalc, Vector](vcalc, initVectorB...)  fmt.Println(va.Value(), vb.Value()) \/\/ {4 -0 -4} {-10 -10 -10}  vsum := ProcessCommands(va, Command[VectorCalc, Vector]{CommandNameAdd, vb}).Value()  fmt.Printf(\"a + b = %v\\n\", vsum) \/\/ a + b = {-6 -10 -14}<\/code><\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 2<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043d\u0435\u043c\u0443\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0430 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0435. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0430 \u0440\u0443\u043a\u0443, \u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u0446\u0435\u043b\u044f\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <code>Calc<\/code> \u0443\u0436\u0435 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 <code>T<\/code> \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code>:<\/p>\n<pre><code class=\"go\">type Calc struct { value float64 }  func NewCalc(value float64) *Calc { return &amp;Calc{value: value} }  func (c *Calc) Add(operand float64) *Calc { c.value += operand return c }  func (c *Calc) Sub(operand float64) *Calc { c.value -= operand return c }  func (c *Calc) Mul(operand float64) *Calc { c.value *= operand return c }  func (c *Calc) Div(operand float64) *Calc { c.value \/= operand return c }  func (c *Calc) Value() float64 { return c.value }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code> \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"go\">type Calculator[T any, V any] interface { Add(operand V) *T Sub(operand V) *T Mul(operand V) *T Div(operand V) *T Value() V }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u0435\u043d, \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b <code>a<\/code> \u0438 <code>b<\/code> \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e \u0436\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"go\">initA := []Command[Calc, float64]{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  initB := []Command[Calc, float64]{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  \/\/ \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u0435\u043d, \u0442\u043e \u0441\u0442\u0430\u0440\u0442\u043e\u0432\u044b\u0445 \u044d\u043a\u0437\u0435\u043f\u043b\u044f\u0440\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u0432\u0430 sum := NewCalc(0) a := ProcessCommands[Calc, float64](sum, initA...) b := ProcessCommands[Calc, float64](NewCalc(0), initB...) \/\/ \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u044f\u0434\u0440\u043e \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e ProcessCommands(a, Command[Calc, float64]{CommandNameAdd, b})  fmt.Printf(\"a + b = %f\\n\", sum.Value()) \/\/ a + b = 9 \/\/ \u0442\u0430\u043a \u043a\u0430\u043a a \u0438 sum \u0441\u0441\u044b\u043b\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u044f\u0434\u0440\u0430, \u0442\u043e fmt.Printf(\"a == sum = %t\\n\", sum.Value() == a.Value()) \/\/ a == sum = true<\/code><\/pre>\n<p>\u041d\u0430 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code> \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043a\u0430\u0436\u0435\u0442, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Calc<\/code> \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[Calc, float64]<\/code>. \u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u043b\u0438\u0448\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043d\u043e \u043d\u0435 \u0441\u0430\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440. \u041e\u0434\u043d\u0430\u043a\u043e \u0442\u0438\u043f <code>T<\/code> \u0443\u0436\u0435 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d \u043a\u0430\u043a <code>T Calculator[T, V]<\/code>, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0438 \u0441\u0430\u043c\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0447\u0442\u043e, \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043d\u0435 \u0442\u0430\u043a.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432 <em>map<\/em> \u0432 \u0432\u0438\u0434\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0438\u043f <code>T any<\/code> \u0438 \u043f\u043e\u043f\u044b\u0442\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u043e\u0439\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u044f\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"go\">calc = calc.Add(command.Operand).(Calculator[T, V])<\/code><\/pre>\n<p>\u041d\u043e \u0438 \u0437\u0434\u0435\u0441\u044c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0436\u0435\u043b\u0430\u044e\u0449\u0435\u0433\u043e \u0442\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u0434\u043e\u043b\u0433\u0438\u0439 \u043f\u0443\u0442\u044c, \u043d\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0439 \u043f\u0438\u043a\u0430\u043d\u0442\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0444\u0430\u043d\u0442\u0430\u0437\u0438\u044f\u043c\u0438. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 \u043f\u043e\u0432\u0435\u0440\u0445\u043d\u043e\u0441\u0442\u0438: \u0435\u0441\u043b\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u0442\u0438\u043f\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435, \u0433\u0434\u0435 \u043e\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e, \u0432\u0435\u0434\u044c \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u0441\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0433\u043b\u0430\u0434\u043a\u043e. \u0415\u0441\u043b\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0442\u043e \u0442\u0438\u043f <code>Calculator[T, V]<\/code> \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442 <code>T<\/code> \u0438 <code>V<\/code>, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u044f\u0432\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<\/p>\n<pre><code class=\"go\">func CastCalc(calc *Calc) Calculator[Calc, float64] { return calc }  func CastVCalc(calc *VectorCalc) Calculator[VectorCalc, Vector] { return calc }<\/code><\/pre>\n<p>\u0427\u0442\u043e \u0436, \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0435\u0433\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"go\">func ProcessCommands[T any, V any](calc Calculator[T, V], cast func(*T) Calculator[T, V], commands ...Command[V]) Calculator[T, V] { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = cast(calc.Add(command.Operand)) case CommandNameSub: calc = cast(calc.Sub(command.Operand)) case CommandNameMul: calc = cast(calc.Mul(command.Operand)) case CommandNameDiv: calc = cast(calc.Div(command.Operand)) } }  return calc }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>main<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"go\">initA := []Command[Calc, float64]{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  initB := []Command[Calc, float64]{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  sum := NewCalc(0) a := ProcessCommands[Calc, float64](sum, CastCalc, initA...) b := ProcessCommands[Calc, float64](NewCalc(0), CastCalc, initB...) ProcessCommands(a, CastCalc, Command[Calc, float64]{CommandNameAdd, b})  fmt.Printf(\"a + b = %f\\n\", sum.Value()) \/\/ a + b = 9 fmt.Printf(\"a == sum = %t\\n\", sum.Value() == a.Value())  initVectorA := []Command[VectorCalc, Vector]{ {CommandNameAdd, NewVectorCalc(Vector{1, 1, 1})}, {CommandNameMul, NewVectorCalc(Vector{2, -2, 2})}, }  initVectorB := []Command[VectorCalc, Vector]{ {CommandNameSub, NewVectorCalc(Vector{10, 10, 10})}, }  vsum := NewVectorCalc(Vector{})  va := ProcessCommands[VectorCalc, Vector](vsum, CastVCalc, initVectorA...) vb := ProcessCommands[VectorCalc, Vector](NewVectorCalc(Vector{}), CastVCalc, initVectorB...)  fmt.Println(va.Value(), vb.Value())  ProcessCommands(va, CastVCalc, Command[VectorCalc, Vector]{CommandNameAdd, vb})  fmt.Printf(\"a + b = %v\\n\", vsum.Value())<\/code><\/pre>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041e\u0431\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435, \u0438\u043c\u0435\u044e\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u044b\u0439 \u0441\u043f\u0435\u043a\u0442\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440 \u0441 \u043d\u0443\u043b\u044f, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044f \u0447\u0442\u043e \u044f\u0434\u0435\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u043a\u0437\u0435\u043f\u043b\u044f\u0440\u043e\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0445\u043e\u0442\u044c \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0442\u0438\u0432\u043e\u0440\u0435\u0447\u0438\u0442 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c Go, \u043e\u0434\u0438\u043d \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043e\u043b\u0436\u0435\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0442\u043e\u0442, \u043a\u0442\u043e \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442, \u0430 \u043d\u0435 \u0442\u043e\u0442, \u043a\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 (\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0439\u0442\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b &#8212; \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0439\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f). \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Calc<\/code> \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441  <code>Calculator<\/code> \u043f\u0440\u0438\u043c\u0443\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"go\">type Calculator[T any] interface { Add(operand T) Calculator[T] Sub(operand T) Calculator[T] Mul(operand T) Calculator[T] Div(operand T) Calculator[T] Value() T }  type Calc struct { value float64 }  func NewCalc(value float64) *Calc { return &amp;Calc{value: value} }  func (c *Calc) Add(operand float64) Calculator[float64] { c.value += operand return c }  func (c *Calc) Sub(operand float64) Calculator[float64] { c.value -= operand return c }  func (c *Calc) Mul(operand float64) Calculator[float64] { c.value *= operand return c }  func (c *Calc) Div(operand float64) Calculator[float64] { c.value \/= operand return c }  func (c *Calc) Value() float64 { return c.value }<\/code><\/pre>\n<p>\u041d\u0438\u043a\u0430\u043a\u0438\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0443\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u0443\u0436\u043d\u044b \u0432 \u0442\u0435\u043b\u0435 <code>ProcessCommands<\/code>, \u043e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u043e \u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Calc<\/code> \u0434\u043e\u043b\u0436\u043d\u0430 \u0437\u043d\u0430\u0442\u044c \u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>Calculator[T]<\/code>, \u0445\u043e\u0442\u044f \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0435\u0433\u043e. \u0414\u0440\u0443\u0433\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0441\u0430\u043c\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <code>Calc<\/code>.<\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0435\u0434\u0438\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0448\u0435 <code>Calc<\/code> \u0438 <code>VectorCalc<\/code>, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0437\u0434\u0435\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0421\u0430\u043c \u0436\u0435 \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <a href=\"https:\/\/bun.uptrace.dev\/\" rel=\"noopener noreferrer nofollow\"><em>bun<\/em><\/a>. \u041e\u043d\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0446\u0435\u043f\u043e\u0447\u043a\u0430\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u043a\u0430\u043a \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <code>bun.SelectQuery<\/code>, \u0442\u0430\u043a \u0438 \u043d\u0430 <code>bun.UpdateQuery<\/code>. \u041c\u043d\u0435 \u0431\u044b\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u043e\u0431\u0430 \u0442\u0438\u043f\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438, \u0445\u043e\u0442\u044f \u0438\u043c\u0435\u043d\u0430 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043e\u0431\u0435\u0438\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b, \u043e\u043d\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0438 \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0432 \u043d\u0435\u0433\u043e:<\/p>\n<pre><code class=\"go\">func (q *UpdateQuery) Where(query string, args ...interface{}) *UpdateQuery  func (q *SelectQuery) Where(query string, args ...interface{}) *SelectQuery  func (q *DeleteQuery) Where(query string, args ...interface{}) *DeleteQuery<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0443 \u0438\u043b\u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e, \u043d\u043e \u0442\u043e\u0442 \u0447\u0435\u0440\u0432\u044c, \u0447\u0442\u043e \u0436\u0438\u0432\u0435\u0442 \u0432 \u043c\u043e\u0435\u043c \u043c\u043e\u0437\u0433\u0443, \u043e\u043f\u044f\u0442\u044c \u043d\u0430\u0447\u0430\u043b \u0437\u0443\u0434\u0435\u0442\u044c \u0438 \u043d\u0430\u0448\u0435\u043f\u0442\u044b\u0432\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438, \u043d\u0435 \u0434\u0430\u0432\u0430\u044f \u0441\u043f\u0430\u0442\u044c \u043f\u043e \u043d\u043e\u0447\u0430\u043c.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c \u0442\u0435\u043c, \u043a\u0442\u043e \u0434\u043e\u0447\u0438\u0442\u0430\u043b \u044d\u0442\u043e\u0442 \u0442\u0435\u043a\u0441\u0442 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u0442\u043e \u043e\u043d \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c, \u0430, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, \u0434\u0430\u0436\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043b \u0432\u0440\u0435\u043c\u044f &#8212; \u0441\u0430\u043c\u044b\u0439 \u0446\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0441\u0443\u0440\u0441 \u0432 \u043d\u0430\u0448\u0435\u0439 \u0436\u0438\u0437\u043d\u0438. \u041a\u0440\u0438\u0442\u0438\u043a\u0430, \u043a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430, \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442\u0441\u044f, \u0434\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0434\u0435\u0438 \u0434\u043e \u0443\u043c\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0438 \u0432\u0435\u0441\u0435\u043b\u0435\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/709438\/\"> https:\/\/habr.com\/ru\/post\/709438\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h2>\n<p>\u0414\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443 \u0442\u0435\u0445, \u043a\u0442\u043e \u043f\u0438\u0448\u0435\u0442 \u043d\u0430 Go \u0431\u044b\u043b\u043e \u0434\u0432\u0430 \u043f\u0443\u0442\u0438: \u043a\u043e\u043f\u0438\u043f\u0430\u0441\u0442\u0430 \u0438 \u043a\u043e\u0434\u043e\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f. \u0424\u0430\u043d\u0430\u0442\u043e\u043c \u043d\u0438 \u043f\u0435\u0440\u0432\u043e\u0433\u043e, \u043d\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u044f \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0441\u044c, \u043e\u0434\u043d\u0430\u043a\u043e \u043a \u043c\u043e\u0435\u0439 \u0440\u0430\u0434\u043e\u0441\u0442\u0438, \u0442\u0435\u043f\u0435\u0440\u044c \u0438 \u0432 Go \u0435\u0441\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0435\u0448\u0435\u043d\u0430! \u041d\u043e \u043d\u0435 \u0442\u0443\u0442-\u0442\u043e \u0431\u044b\u043b\u043e, \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 Go \u0438\u043c\u0435\u044e\u0442 \u0432\u0435\u0441\u044c\u043c\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, <em>\u043f\u043e\u0440\u0442\u044f\u0442 \u0432\u0441\u044e \u043c\u0430\u043b\u0438\u043d\u0443<\/em>. \u0421 \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u043d\u0438\u0445 \u043c\u043d\u0435 \u0438 \u0437\u0430\u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h2>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u0442\u0438\u043a\u0430<\/h2>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041d\u0438\u0436\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f &#171;\u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 Go, \u0438 \u043a\u0430\u043a \u0441 \u043d\u0438\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c&#187;, \u0437\u0430 \u0441\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0441\u0430\u0439\u0442 \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u0433\u0434\u0435 \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0436\u0435\u0432\u0430\u043d\u043e.<\/p>\n<p>\u0412\u043e\u0437\u044c\u043c\u0435\u043c, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u043f\u0430\u0442\u0442\u0435\u0440\u043d <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%A1%D1%82%D1%80%D0%BE%D0%B8%D1%82%D0%B5%D0%BB%D1%8C_(%D1%88%D0%B0%D0%B1%D0%BB%D0%BE%D0%BD_%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%82%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D1%8F)\" rel=\"noopener noreferrer nofollow\"><em>\u0441\u0442\u0440\u043e\u0438\u0442\u0435\u043b\u044c (builder)<\/em><\/a> \u0438 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043c \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0443\u043c\u0435\u0442\u044c \u043b\u0438\u0448\u044c \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c, \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c, \u0434\u0435\u043b\u0438\u0442\u044c, \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u043d\u043e\u0432\u044b\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"go\">type Calc struct { value float64 }  func NewCalc(value float64) Calc { return Calc{value: value} }  func (c Calc) Add(operand float64) Calc { return Calc{value: c.value + operand} }  func (c Calc) Sub(operand float64) Calc { return Calc{value: c.value - operand} }  func (c Calc) Mul(operand float64) Calc { return Calc{value: c.value * operand} }  func (c Calc) Div(operand float64) Calc { return Calc{value: c.value \/ operand} }  func (c Calc) Value() float64 { return c.value }<\/code><\/pre>\n<p>\u041f\u0443\u0441\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c\u0441\u044f \u044f\u0434\u0440\u043e\u043c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043f\u0430\u0440\u0443 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<pre><code class=\"go\">calc := NewCalc(0)  a := calc.Add(6).Mul(3).Div(2).Sub(1).Value() \/\/ 8 b := calc.Sub(10).Div(2).Add(6).Value() \/\/ 1  fmt.Printf(\"a + b = %f\\n\", calc.Add(a).Add(b).Value()) \/\/ a + b = 9<\/code><\/pre>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>Calc<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439, \u0430 \u043c\u044b \u043b\u0438\u0448\u044c \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u043d\u0435\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u044e\u0449\u0438\u0445 \u043e\u0442\u043a\u0443\u0434\u0430-\u0442\u043e \u0438\u0437\u0432\u043d\u0435.<\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435:<\/strong> \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u044b\u0448\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0439 \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0430\u043c \u043a\u043e\u0434 \u044f\u0434\u0440\u0430 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 \u0434\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434, \u0447\u0435\u043c \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443.<\/p>\n<pre><code class=\"go\">type CommandName uint8  \/\/ \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430. const ( CommandNameAdd CommandName = iota CommandNameSub CommandNameMul CommandNameDiv )  \/\/ \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0430\u044f \u0438\u043c\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u043e\u043f\u0435\u0440\u0430\u043d\u0434. type Command struct { Name    CommandName Operand Calc }  \/\/ \u041f\u0430\u043a\u0435\u0442\u043d\u0430\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 func ProcessCommands(calc Calc, commands ...Command) Calc { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c, \u0438\u043c\u0435\u044f \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 <code>Calc<\/code> \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0432\u0438\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code>, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0438\u0437\u0432\u043d\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0434\u043d\u0438\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c:<\/p>\n<pre><code class=\"go\">calc := NewCalc(0)  \/\/ \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 a \u0438 b \u0445\u0440\u0430\u043d\u0438\u043c \u0443\u0436\u0435 \u043d\u0435 \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 a := ProcessCommands(calc, Command{CommandNameAdd, NewCalc(6)}, Command{CommandNameMul, NewCalc(3)}, Command{CommandNameDiv, NewCalc(2)}, Command{CommandNameSub, NewCalc(1)}, )  b := ProcessCommands(calc, Command{CommandNameSub, NewCalc(10)}, Command{CommandNameDiv, NewCalc(2)}, Command{CommandNameAdd, NewCalc(6)}, )  \/\/ \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 (`a`) \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u043c\u043c\u044b sum := ProcessCommands(a, Command{CommandNameAdd, b}).Value() fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9<\/code><\/pre>\n<p>\u0414\u0430, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u0442\u0430\u043a \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u0437\u0430\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0434\u043e \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0438\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437:<\/p>\n<pre><code class=\"go\">\/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 A initA := []Command{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043c\u043e\u0434\u0443\u043b\u0435 B initB := []Command{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  \/\/ \u0433\u0434\u0435-\u0442\u043e \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 calc := NewCalc(0)  a := ProcessCommands(calc, initA...) b := ProcessCommands(calc, initB...) sum := ProcessCommands(a, Command{CommandNameAdd, b}).Value()  fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0443\u0436\u0435 \u043d\u0435 \u0441\u0442\u043e\u043b\u044c \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u043c, \u0438 \u043c\u043e\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430 (<em>M+<\/em>, <em>M-<\/em>, <em>MC<\/em>) \u0431\u0435\u0437 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u044f\u0434\u0440\u0430, \u0447\u0442\u043e, \u0432\u043f\u0440\u043e\u0447\u0435\u043c, \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0442\u0435\u043c\u044b.<\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u043c\u0435\u044e\u0442\u0441\u044f: \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0438\u0445 \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0438 \u0431\u0435\u0437\u0443\u043c\u043d\u0430\u044f \u043c\u044b\u0441\u043b\u044c \u0432 \u0433\u043e\u043b\u043e\u0432\u0435&#8230; \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0435 \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0435 \u0441\u043a\u0430\u043b\u044f\u0440\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0430 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u0435? \u041d\u0430\u0431\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u043f\u0443\u0441\u043a\u0430\u0439, \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u0435\u0442\u043e\u0434\u044b \u0442\u0438\u043f\u0430 \u0443\u043c\u043d\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u043a\u0430\u043b\u044f\u0440 \u043e\u0442\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0437\u0430 \u0431\u043e\u0440\u0442. \u0421\u043a\u0430\u0437\u0430\u043d\u043e &#8212; \u0441\u0434\u0435\u043b\u0430\u043d\u043e:<\/p>\n<pre><code class=\"go\">type Vector struct { X float64 Y float64 Z float64 }  type VectorCalc struct { value Vector }  func NewVectorCalc(value Vector) VectorCalc { return VectorCalc{value: value} }  func (c VectorCalc) Add(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.X + operand.X, Y: c.value.Y + operand.Y, Z: c.value.Z + operand.Z, }, } }  func (c VectorCalc) Sub(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.X - operand.X, Y: c.value.Y - operand.Y, Z: c.value.Z - operand.Z, }, } }  func (c VectorCalc) Mul(operand Vector) VectorCalc { return VectorCalc{ value: Vector{ X: c.value.Y*operand.Z - c.value.Z*operand.Y, Y: -(c.value.Z*operand.X - c.value.X*operand.Z), Z: c.value.X*operand.Y - c.value.Y*operand.X, }, } }  func (c VectorCalc) Div(operand Vector) VectorCalc { \/\/ \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0432\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0432 \u043e\u0431\u0449\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 panic(\"operation is not defined\") }  func (c VectorCalc) Value() Vector { return c.value }<\/code><\/pre>\n<p>\u041d\u0435 \u0442\u0440\u0443\u0434\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u043e\u0431\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441:<\/p>\n<pre><code class=\"go\">type Calculator[T any, V any] interface { Add(operand V) T Sub(operand V) T Mul(operand V) T Div(operand V) T Value() V }<\/code><\/pre>\n<p>\u041b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u0442\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f \u043e\u043f\u0435\u0440\u0430\u043d\u0434\u0430 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0442\u0438\u043f\u044b \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"go\">type Command[T any, V any] struct { Name    CommandName Operand Calculator[T, V] }  func ProcessCommands[T any, V any](calc Calculator[T, V], commands ...Command[T, V]) Calculator[T, V] { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0443\u0440\u043e\u0432\u0430\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0431\u044c\u0435\u0442 \u043f\u043e \u0433\u043e\u043b\u043e\u0432\u0435, \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>T<\/code> \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code>. \u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u0432\u0435\u0434\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e <code>T<\/code> &#8212; \u044f\u0434\u0440\u043e \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>ProcessCommands<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 <code>calc<\/code>, \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 &#8212; \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 &#8212; \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 <code>T<\/code> \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0433\u043b\u0430\u0441\u0438\u0442, \u0447\u0442\u043e <code>T<\/code> &#8212; \u044d\u0442\u043e \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f (<code>any<\/code>), \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043d\u0438\u043a\u0430\u043a \u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e <code>T<\/code> \u044d\u0442\u043e \u0432\u0441\u0435 \u0442\u043e\u0442 \u0436\u0435 \u0442\u0438\u043f, \u0447\u0442\u043e \u0438 <code>Calculator[T, V]<\/code>.<\/p>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 1<\/h2>\n<p>\u0427\u0442\u043e \u0436, \u043d\u0435 \u0431\u0435\u0434\u0430, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438 \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"go\">func ProcessCommands[T Calculator[T, V], V any](calc Calculator[T, V], commands ...Command[T, V]) Calculator[T, V] { for _, command := range commands { switch command.Name { case CommandNameAdd: calc = calc.Add(command.Operand.Value()) case CommandNameSub: calc = calc.Sub(command.Operand.Value()) case CommandNameMul: calc = calc.Mul(command.Operand.Value()) case CommandNameDiv: calc = calc.Div(command.Operand.Value()) } }  return calc }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u044b\u043c \u044f\u0434\u0440\u043e\u043c:<\/p>\n<pre><code class=\"go\">initA := []Command[Calc, float64]{ {CommandNameAdd, NewCalc(6)}, {CommandNameMul, NewCalc(3)}, {CommandNameDiv, NewCalc(2)}, {CommandNameSub, NewCalc(1)}, }  initB := []Command[Calc, float64]{ {CommandNameSub, NewCalc(10)}, {CommandNameDiv, NewCalc(2)}, {CommandNameAdd, NewCalc(6)}, }  calc := NewCalc(0)  a := ProcessCommands[Calc, float64](calc, initA...) b := ProcessCommands[Calc, float64](calc, initB...) sum := ProcessCommands(a, Command[Calc, float64]{CommandNameAdd, b}).Value()  fmt.Printf(\"a + b = %f\\n\", sum) \/\/ a + b = 9  initVectorA := []Command[VectorCalc, Vector]{ {CommandNameAdd, NewVectorCalc(Vector{1, 1, 1})}, {CommandNameMul, NewVectorCalc(Vector{2, -2, 2})}, }  initVectorB := []Command[VectorCalc, Vector]{ {CommandNameSub, NewVectorCalc(Vector{10, 10, 10})}, }  vcalc := NewVectorCalc(Vector{})  va := ProcessCommands[VectorCalc, Vector](vcalc, initVectorA...) vb := ProcessCommands[VectorCalc, Vector](vcalc, initVectorB...)  fmt.Println(va.Value(), vb.Value()) \/\/ {4 -0 -4} {-10 -10 -10}  vsum := ProcessCommands(va, Command[VectorCalc, Vector]{CommandNameAdd, vb}).Value()  fmt.Printf(\"a + b = %v\\n\", vsum) \/\/ a + b = {-6 -10 -14}<\/code><\/pre>\n<h2>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 2<\/h2>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043d\u0435\u043c\u0443\u0442\u0438\u0440\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u043e \u0435\u0441\u0442\u044c \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043f\u0438\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u0430 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0435. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043a\u0430\u043b\u044c\u043a\u0443\u043b\u044f\u0442\u043e\u0440\u043e\u043c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u043c \u0434\u0430\u0436\u0435 \u043d\u0430 \u0440\u0443\u043a\u0443, \u043d\u043e \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 \u0446\u0435\u043b\u044f\u0445 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u0438\u0431\u043e \u043f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <code>Calc<\/code> \u0443\u0436\u0435 \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 <code>T<\/code> \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>ProcessCommands<\/code>:<\/p>\n<pre><code class=\"go\">type Calc struct { value float64 }  func NewCalc(value float64) *Calc { return &amp;Calc{value: value} }  func (c *Calc) Add(operand float64) *Calc { c.value += operand return c }  func (c *Calc) Sub(operand float64) *Calc { c.value -= operand return c }  func (c *Calc) Mul(operand float64) *Calc { c.value *= operand return c }  func (c *Calc) Div(operand float64) *Calc { c.value \/= operand return c }  func (c *Calc) Value() float64 { return c.value }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>Calculator[T, V]<\/code> \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"go\">type Calculator[T any, V any] interface { Add(operand V) *T Sub(operand V) *T Mul(operand V) *T Div(operand V) *T Value() V }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u0435\u043d, \u043d\u0443\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043a\u043e\u0434, \u0447\u0442\u043e\u0431\u044b <code>a<\/code> \u0438 <code>b<\/code> \u043d\u0435<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343632","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343632","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343632"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343632\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}