Kotlin's Scan Function, Fantastic Learning Paths, And More - Weekly Tech Tidbits #5
Explore roadmap.sh for Learning, Kotlin's Scan Function, and Google Cloud Region Picker for Optimal Cloud Service Choices
Hi π, it's great to have you here for this issue of Weekly Tech Tidbits. In today's post, we'll cover three intriguing topics:
Master Your Learning Paths with roadmap.sh π
Kotlin Gems: The Scan Function π
Google Cloud Region Picker π
Enjoy reading and feel free to share your thoughts in the comments below. Don't forget to subscribe for more insights and share this post with your network! π’
Master Your Learning Paths with roadmap.sh π
Learning new things is hard, especially when you don't know what you need to learn. This is where roadmap.sh comes in. They provide visual graphs of learning content for a wide array of development topics, such as backend, frontend, system design, and more.
While the site itself offers limited content, it provides valuable links for deeper exploration of these topics. If you log in, you can even track your own progress.
This site is incredibly useful if you want to dive into a new topic π‘. Recently, they launched a feature to create roadmaps on anything via AI. While I'm not yet convinced by the quality (the hand-curated ones are much better), itβs fun to try out.
Kotlin Gems: The Scan Function π
The scan
function in Kotlin is a hidden gem for processing collections, similar to fold
but with a twist. While fold
accumulates values to a final result, scan
retains all intermediate results, perfect for tasks like running totals or cumulative distributions.
Using scan
, you can track the progression of computations π. Hereβs an example:
val donations = listOf(10, 15, 20, 25, 30)
val runningTotal = donations.scan(0) { total, donation -> total + donation }
This code snippet starts with a running total of 0, sequentially adding each donation and capturing each intermediate state along the way. The scan
function generates the following list: [0, 10, 25, 45, 70, 100]
, providing a detailed view of the accumulation process.
While both scan
and fold have
a similar function signature, they serve distinct purposes. Fold
returns only the final accumulated value, which is suitable for scenarios where you only need the end result. Hereβs an example demonstrating fold:
val donations = listOf(10, 15, 20, 25, 30)
val totalDonations = donations.fold(0) { total, donation -> total + donation }
}
This results in 100
, giving you the cumulative sum without the intermediate steps.
The choice between scan and fold depends on your needs: use scan
for visibility into each step of the accumulation, and fold
when only the final result matters.
Google Cloud Region Picker π
Choosing the right region for your cloud services can be challenging. The most important factor is proximity to your users, but costs and carbon footprint are also factors to consider.
I was surprised to discover that Google Cloud services can have different costs depending on the region. For instance, running Cloud Run instances in europe-west1 is cheaper than in europe-west3. Additionally, not all services are available in every regionβCloud Scheduler, for example, is only available in four regions in Europe.
The Google Cloud Region Picker simplifies this process, helping you select the most suitable region for your needs.
By setting just a few parameters, you'll receive a list of the best-fit regions for your services. This tool makes it much easier than digging through extensive documentation!
Wrapping Up
Thank you for reading this week's Weekly Tech Tidbits. Here's a quick recap:
Master Your Learning with roadmap.sh: Simplify your learning journey with visual roadmaps for various development topics.
Kotlin Gems: The Scan Function: Utilize the scan function for tracking the progression of computations and gaining intermediate results.
Google Cloud Region Picker: Select the most suitable region for your cloud services based on proximity, cost, and availability.
I'd love to hear your thoughts, questions, and feedback in the comments below. π¬ Don't forget to subscribe for more insights π and share this post with your network! π’
Stay tuned for next week's post.