Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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