Over the last week or so, I’ve been looking at and playing around with the Streams API in Dart, which has been (in part at least) based on the Rx API, and it’s easy to see the parallels between the two sets of APIs and you can find most of the core Rx APIs on Dart’s Stream type already, but there were a few notable absentees which I have often found useful, such as merge, zip, delay and window.
With these absentees in mind I started a small Dart project called stream_ext (for stream extensions) to port them over, and here are some details of the first couple of functions I have done along with some live demo examples.
The merge function merges two streams into a single unified output stream.
The combineLatest function merges two streams into one by using the supplied selector function whenever one of the streams produces an event.
The delay function creates a new stream whose events are directly sourced from the input stream but each delivered after the specified duration.
The throttle function creates a new stream based on events produced by the specified input, upon forwarding an event from the input stream it’ll ignore any subsequent events produced by the input stream until the flow of new events has paused for the specified duration, after which the last event produced by the input stream is then delivered.
The zip function combines two streams into one by combining their elements in a pairwise fashion, combining the latest value on each stream and producing a new event using the supplied zipper function.
It’s still early days and there are quite a few more useful Rx function I think will be useful to people working with Dart, and I hope you find these extension functions useful and please don’t hesitate to get in touch and leave some feedbacks on the project!
I specialise in rapidly transitioning teams to serverless and building production-ready services on AWS.
Are you struggling with serverless or need guidance on best practices? Do you want someone to review your architecture and help you avoid costly mistakes down the line? Whatever the case, I’m here to help.
Check out my new course, Complete Guide to AWS Step Functions. In this course, we’ll cover everything you need to know to use AWS Step Functions service effectively. Including basic concepts, HTTP and event triggers, activities, callbacks, nested workflows, design patterns and best practices.
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are thinking about serverless costs all wrong
- Many faced threats to Serverless security
- We can do better than percentile latencies
- I’m afraid you’re thinking about AWS Lambda cold starts all wrong
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong