Title: Chain
Open Graph Title: Python itertools.chain and (++)
Description: To concatenate two Python iterators, we use ‘itertools.chain’. The resulting iterator consists of each element from the first argument, followed by each element of the second argument. The corresponding Haskell function is called (++). The ‘chain’ function is variadic; it can accept any number of arguments, not just two. This makes it easy to chain together any number of iterators without having to use nested function applications. Haskell doesn’t have variadic functions, but it does let you define infix operators, which can be used to get a similar convenient effect. The (++) function concatenates exactly two lists, but infix notation makes it easy to chain together as many concatenations as you like. If you aren’t chaining together some fixed number of lists, but rather a list of lists, you can use ’chain.from_iterable’. The Haskell equivalent is called ‘concat’.
Open Graph Description: To concatenate two Python iterators, we use ‘itertools.chain’. The corresponding Haskell function is called (++).
X: @typeclasses
Domain: typeclasses.com
| theme-color | #31365f |
| og:image | https://static.typeclasses.com/twitter-python__itertools-chain-c196d36b30.png |
| og:type | article |
| article:tag | lists |
| twitter:card | summary_large_image |
Links:
Viewport: width=device-width, initial-scale=1