Skip to content

Wrap Translation::Peek() and Translation::Next()#352

Open
ksqsf wants to merge 2 commits intohchunhui:masterfrom
ksqsf:master
Open

Wrap Translation::Peek() and Translation::Next()#352
ksqsf wants to merge 2 commits intohchunhui:masterfrom
ksqsf:master

Conversation

@ksqsf
Copy link
Contributor

@ksqsf ksqsf commented Jun 7, 2024

有的时候只需要简单地查看前一两个候选,直接使用 Peek() 和 Next() 会比 iter() 方便一点。

@shewer
Copy link
Contributor

shewer commented Jun 8, 2024

#272

@ksqsf
Copy link
Contributor Author

ksqsf commented Jun 12, 2024

i see. 不过我不太赞同「有了 iter 就不要其他接口」。比如想抛弃 sentence 的时候,如果有 peek,我可以保留其他代码,而不用引入别的代码。

if tran:peek() and tran:peek().type == "sentence" then
  tran:next()
end

-- other logic
yield(cand1)
yield(cand2)
--

for cand in tran:iter() do
  yield(cand)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants