"""the higherOrder function return a lambda function
Args:
n (int): divisor(is used for judging the integer x whether could be divisible by n)
Returns:
a lambda function: to judge the divisible(return the bool value(True/False),we want to filter the integer which couldn't be divisible by n,to make up(generate) the new sequence)
"""
""" return the lambda function:x is the parameter of the lambda expression
because we need to pass two parameter :element from iterator;the prime number to be the divisor
we could return a lambda function to achieve it:the lambda contains two variable:x(passed from the iterator to be the divisor),n(passed from _not_divisible())"""
""" write the doc for the lambda:
x:the element of the iterator"""
returnlambda x: x % divisor > 0
""" 最后,定义一个生成器,不断返回下一个素数: """
defprimes():
"""calculate the prime number
Yields:
[int]: [the calculate result ]
"""
""" initial return(yield) the specific prime :2 """
yield2
"""bind the odd integers generator to the variable it
"""
it = _odd_iter() # 初始序列(iterator) the statement will just be execute once,then the while loop will update the iterator
whileTrue:
# 返回序列的第一个数(this number will be the screen(filter) to be the parameter of the _notdivisible())
""" get a element from the _odd_iter() ,assign to it(int type) """
n = next(it)
""" pop the first element of the number sequence--the next prime number"""
yield n
# 通过筛选函数,再次执行以n为筛子进行筛选,构造新序列(update the iterator to iterate the process)
""" update the iterator :use the prime founded (it is:n)just now to be the divisor to generator a new iterator represent the new sequence
the filter is:judge the element of iterator which make the filter function return True"""
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了