From 00394a80501960ad26787b5c44435ed5ed67ad84 Mon Sep 17 00:00:00 2001 From: Alexander Neonxp Kiryukhin Date: Mon, 9 Mar 2026 23:05:42 +0300 Subject: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D1=83.?= =?UTF-8?q?=20=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D1=91=D0=BB=20=D1=81=20EBNF?= =?UTF-8?q?=20=D0=BD=D0=B0=20PEG.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/model.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 model/model.go (limited to 'model/model.go') diff --git a/model/model.go b/model/model.go new file mode 100644 index 0000000..2bc6dfb --- /dev/null +++ b/model/model.go @@ -0,0 +1,44 @@ +package model + +import ( + "iter" +) + +type Ident string + +type Command struct { + Name Ident + Args []any + Group Group +} + +// Value returns first argument of command. +func (c *Command) Value() any { + if len(c.Args) > 0 { + return c.Args[0] + } + return nil +} + +type Group []Command + +// Get returns first command with given name. +func (g Group) Get(name Ident) *Command { + for _, c := range g { + if c.Name == name { + return &c + } + } + return nil +} + +// Filter commands by predicate and returns iterator over filtered commands. +func (g Group) Filter(predicate func(c *Command) bool) iter.Seq[*Command] { + return func(yield func(*Command) bool) { + for _, c := range g { + if predicate(&c) && !yield(&c) { + return + } + } + } +} -- cgit v1.2.3