avatarAiden (Illumination Gaming)

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3392

Abstract

er">17</span>]</pre></div><blockquote id="c020"><p>Compact Map()</p></blockquote><p id="b1c2"><code>compactMap</code> function is similar to <code>map</code>, but it also includes an additional step, it filters out any <code>nil</code> values that result from applying the transformation closure. This is particularly useful when you have an array of optional values and you want to transform them while simultaneously filtering out the <code>nil</code> elements.</p><div id="9cf9"><pre><span class="hljs-keyword">extension</span> <span class="hljs-title class_">Array</span> { <span class="hljs-keyword">func</span> <span class="hljs-title function_">compactMap</span><<span class="hljs-type">T</span>>(<span class="hljs-keyword">_</span> <span class="hljs-params">transforms</span>: (<span class="hljs-type">Element</span>) -> <span class="hljs-type">T</span>?) -> [<span class="hljs-type">T</span>] { <span class="hljs-keyword">var</span> result <span class="hljs-operator">=</span> <span class="hljs-type">T</span> <span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> <span class="hljs-keyword">self</span> { <span class="hljs-keyword">if</span> <span class="hljs-keyword">let</span> element <span class="hljs-operator">=</span> element { result.append(transform(element)) } } <span class="hljs-keyword">return</span> result } }</pre></div><p id="fe9c">Here the only change from <code>Map</code> and <code>Compact Map</code> is avoiding the nil value with a condition.</p><p id="3b42">In the above code</p><ul><li>It takes a closure <code>transform</code> as an argument, which specifies how each element should be transformed.</li><li>Inside <code>compactMap</code>, a new array <code>result</code> is created to store the transformed non-nil elements.</li><li>It then iterates over each element of the original array (<code>self</code>), applies the transformation closure to each element, and checks if the result is non-nil.</li><li>If the result is non-nil, it appends the transformed element to the <code>result</code> array.</li><li>Finally, it returns the <code>result</code> array containing all the non-nil transformed elements.</li></ul><blockquote id="9909"><p>How to consume it?</p></blockquote><div id="41f1"><pre><span class="hljs-keyword">let</span> mapArray <span class="hljs-operator">=</span> [<span class="hljs-number">23</span>, <span class="hljs-number">43</span>, <span class="hljs-number">56</span>, <span class="hljs-literal">nil</span>, <span class="hljs-number">75</span>, <span class="hljs-number">9</span>, <span class="hljs-number">14</span>] <span class="hljs-keyword">let</span> result<span class="hljs-operator">=</span> mapArray.compactMap { <span class="hljs-variable">$0</span> } <span class="hljs-built_in">debugPrint</span>(result) output: [<span class="hljs-number">23</span>, <span class="hljs-number">43</span>, <span class="hljs-number">56</span>, <span class="hljs-number">75</span>, <span class="hljs-number">9</span>, <span class="hljs-number">14</span>]</pre></div><blockquote id="854c"><p>Flat Map()</p></blockquote><p id="b656">FlatMap is typically the same as <code>map</code> does, only difference is that it always return flatten array joining all elements. Typically used to collect specific data in n

Options

ested array, dictionary or set</p><div id="6431"><pre><span class="hljs-keyword">extension</span> <span class="hljs-title class_">Array</span> { <span class="hljs-keyword">func</span> <span class="hljs-title function_">flatMap</span><<span class="hljs-type">T</span>>(<span class="hljs-keyword">_</span> <span class="hljs-params">transform</span>: (<span class="hljs-type">Element</span>) -> [<span class="hljs-type">T</span>]) -> [<span class="hljs-type">T</span>] { <span class="hljs-keyword">var</span> result <span class="hljs-operator">=</span> <span class="hljs-type">T</span> <span class="hljs-keyword">for</span> element <span class="hljs-keyword">in</span> <span class="hljs-keyword">self</span> { result.append(contentsOf: transform(element)) } <span class="hljs-keyword">return</span> result } }</pre></div><p id="75fa">In the above code</p><ul><li>It takes a closure <code>transform</code> as an argument, which specifies how each element should be transformed into a sequence.</li><li>Inside <code>flatMap</code>, a new array <code>result</code> is created to store the flattened elements.</li><li>It then iterates over each element of the original array (<code>self</code>), applies the transformation closure to each element, and concatenates the resulting sequences into the <code>result</code> array.</li><li><code>append(contentsOf: )</code> will add the elements of a sequence to the end of the array.</li><li>Finally, it returns the <code>result</code> array containing all the flattened elements.</li></ul><blockquote id="2285"><p>How to consume it?</p></blockquote><div id="117f"><pre><span class="hljs-keyword">let</span> arrayOfArrays <span class="hljs-operator">=</span> [[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>], [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]] <span class="hljs-keyword">let</span> transformedArray <span class="hljs-operator">=</span> arrayOfArrays.flatMap { <span class="hljs-variable">$0</span> } <span class="hljs-built_in">print</span>(transformedArray) output: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]</pre></div><h1 id="3bda">Conclusion</h1><p id="057c">There are plenty of other use cases for higher-order functions. This is a gist of what we have discovered today:</p><ul><li>If you need to simply transform a value to another value, then use <code>map</code>.</li><li>If you need to remove nil values, then use <code>compactMap</code>.</li><li>If you need to flatten your result one level down, then use <code>flatMap</code>.</li></ul><p id="0a10">Thank you for your time and attention! 👏👏👏</p><p id="33e6">Do clap👏 if you like this and comment your suggestions!!! <i>Happy coding</i>!!!</p><blockquote id="1e0c"><p>Source Code: <a href="https://github.com/Vikassingamsetty/HigherOrderFunctions.git">GitHub</a></p></blockquote></article></body>

Gaming and Technology

Logitech G and Tencent Games Announces Handheld Cloud Gaming Console

Here is a compact device that only requires an internet connection to play whatever game they want.

Photo by Pixabay on Pexels

About Logitech G

First I’d like to give a brief introduction to Logitech G and Tencent Games.

Logitech G is the global leader in PC and console hardware. They manufacture industry-leading keyboards, mice, headsets, and simulation products.

From my reviews, Tencent Games is one of the world’s leading video game vendors. They provide high-quality interactive entertainment experiences to players.

The company also offers more than 140 games currently.

Partnership Between Logitech G and Tencent Games

On the 2nd of August 2022, Logitech G and Tencent Games announced a partnership between the two.

They are currently developing a handheld cloud gaming console which will come to the market later this year.

The device will be a combination of Logitech Gs expertise in hardware and Tendent Games’ expertise in software services.

This handheld console will support multiple cloud gaming services such as Xbox Cloud Gaming and Nvidia Geforce NOW.

Not much is known about the specifications or looks of the device itself, but hopefully, we’ll get more news soon.

The idea is that this handheld console will exclusively be used for cloud gaming. Users will not have to download anything onto the device.

You will just be able to pick up the device and start playing games through the cloud.

About Cloud Gaming

Essentially how cloud gaming works is it utilizes data center servers from many part of the world to stream games to users.

There is absolutely no need to download or install anything relating to the games you wish to play.

The games are rendered and played on remote servers, which users interact with on their local devices.

If you ask me, this delivery approach sounds like something from the future.

It seems so surreal to play games through the Cloud without having to own a dedicated device to run such games.

As you can imagine, since the device isn’t using its own hardware to run these games, the form factor will most likely be very slim.

Recent speculations suggest the device will be the approximate size of a Nintendo Switch, with a screen in the middle and controls on either side.

Final Thoughts

In my opinion, this device will essentially be a one-up from the mobile gaming experience.

Since mobile phones have the ability to stream games through the cloud, it seems to me this device would be best suited for people who want to continue with their mobile gaming experience but on a dedicated device with better controls and a nicer interface.

This seems like a genuinely good way to ease people into the cloud gaming world.

I’m looking forward to the day gamers don’t need a dedicated PC or console to game on.

Just a compact device that only requires an internet connection to play whatever game they want.

I believe the future of gaming will be through the Cloud Computing. Exciting times are ahead. I love the power of technology on the gaming industry.

I recently read a book chapter of Dr Mehmet Yildiz about Cloud Computing published on Medium. I link the article for those who might want to know more about this interesting technology domain.

Thank you for reading my story. I wish you a prosperous life.

About My Content and Editorial Duties on Medium

I write about gaming and social media topics. In addition, I am the owner and editor of two publications on Medium. One is for YouTubers, and another one is for gamers.

Some YouTubers are also gamers, so they are welcome to join both publications. If you are interested in these topics, I look forward to hosting your stories and promoting them.

You might check the invitations providing the scope of publications and details to join them if you are interested.

Invitation: Join ILLUMINATION Gaming Publication as a Writer

Invitation to Write for ILLUMINATION on YouTube Publication

Writer applications can be sent via this weblink.

Sample Gaming Stories In My Collection

PlayStation Games That Are Finally Coming To PC

Stray Is a Wholesome Cat Adventure Game We Didn’t Know We Needed

The Backbone One: An Excellent Controller For Mobile Gaming

A New Hope For Portable Gaming

Let’s Talk About Gaming Simulators Today.

Finally, I Read and Heard Interesting Rumors About Grand Theft Auto 6.

Playstation 5: There’s Demand But No Supply.

The Rise, Fall, and Rise of Fall Guys

Turbo Golf Racing Is on Its Way!

Multiversus’ Announcement Excited Me Beyond Words.

Splitgate: An Interesting Take on the FPS Gaming Genre

Let’s Talk About eSports Today.

How Pay-To-Win Games Ruin Player Experience

My Top Five Most Nostalgic Games

How Mobile Gaming Has Evolved

Here’s How Minecraft Evolved Over the Years

Beginners Guide to Gaming Gear and Peripherals

Let’s Talk About Game Launchers and Storefronts

High on Life: The Upcoming Game Set in the Rick & Morty Universe

Five Exciting New Games Releasing This Year

Massively Multiplayer Online Role-Playing Games

The All-New PlayStation Plus Is Finally Here

Overwatch 2 Is Almost Here

What Computer Games Mean to Me and Why I Play Them

Do You Want to Learn How Slot Machines Work?

Let’s Talk About Idiosyncrasies of Teabagging in Gaming

Tribute to Technoblade (aka Alex) RIP

Recent Stories on Other Topics

Why Elon Musk Sold His Bitcoin Shares Out of Blue

Covid Virus Finally Infected Me Despite Intense Cautions.

Why Everyone Unfollowed Me Today

The Follower Bug Manifests in Different Shapes and Forms

If you have had similar experiences, please share.

I enjoy collaborating with writers and introducing them on YouTube. Here is a link to my collection: Meet Top Writers on YouTube. It includes an introduction to prolific writers of Illumination Integrated Publications on Medium in YouTube videos.

Connection with Writers and Readers on Medium

I write informative and inspiring articles in my field covering gaming, film-making, media, and design. You can subscribe to my account to get notifications when I post on Medium.

I also support Illumination Integrated Publications as a volunteer editor and participate in collaborative activities in the Slack Workspace.

Gaming
Gaming News
Social Media
Technology
Cloud Computing
Recommended from ReadMedium