Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Пример функтора.
- X = [1, 2, 3]
- >>> mp = map(lambda x:x*2, x)
- >>> list(mp)
- [2, 4, 6]
- def positive_and_negative(x):
- return List(x, -x)
- List(9) >> positive_and_negative # Результатом станет монада List(9, -9)
- def add_and_sub(x, y):
- return List(y + x, y - x)
- List(2) >> add_and_sub(3) # Вернет список List(5, -1)
- List(2) >> positive_and_negative >> add_and_sub(3) # Результатом станет List(5, -1, 1, -5)
Advertisement
Add Comment
Please, Sign In to add comment