avatarNapoleon

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>

Social Media superstar Mia Khalifa

How Mia Khalifa’s Rebrand Makes Her $6.42 Million a Month

“You should have read the fine print. It says no nudity. Respect the rebrand.” — M. Khalifa

Not Mia Khalifa Photo by Austin Guevara

Who wouldn’t know her? Mia Khalifa caused a firestorm when she wore a hijab in an adult video she made when she was 21. There you have it, yes, she is a former porn star but today she has rebranded herself as a social media superstar.

Mia Khalifa now has over 32 million followers on TikTok and almost 28 million followers on Instagram. She’s one of the top 50 content creators on TikTok.

In 2020, she created her account on OnlyFans, and today she earns $6.42 million a month from her almost half a million paying subscribers.

She is also one of the top 10 celebrity earners on the social media platform.

If you haven’t heard about OnlyFans it’s a social media platform like any other with the exception of a payment button.

The road to her new life wasn’t an easy journey for M. Khalifa. Even today, men try to make her not forget her previous life.

After her interview with Bustle came out, men on Twitter trolled her. Well, she doesn’t take crap from men, when the troll tweeted her —

Maybe not wear a boob sweater to draw attention?

She replied, ‘I’m wearing Paco Rabanne, you fu*king peasant.’

Is this happiness?

I love what she said in her interview with Bustle.

Is this normal? Is this happiness?”

She can’t believe that today she found herself in a better place, a far cry from the notoriety of being known as the porn star who wore a hijab. And all that controversy, all that backlash and death threats from ISIS sympathizers for $12,000, the money she made in her short career as an adult film actor.

She left the porn industry after three months.

In this interview from BBC HARDtalk, she doesn’t call herself a victim. She takes 100% ownership of her decisions; she has learned to forgive her 21-year-old self.

Her decision to make adult videos was an act of rebellion. She thought it could be her dirty little secret. She didn’t want to be famous.

She believed she could be one of the thousands of young women who remain nameless but as fate would have it, she became infamous.

Disowned by her family, she could have gone down the rabbit hole of despair, instead, she owned her past, made peace with herself, and charted a new territory away from the adult entertainment industry.

How Mia Khalifa rebranded herself and made more money than she ever thought possible

When a young woman on TikTok shared her experience as a 13-year-old girl bullied by her classmates because of her glasses and they teased her that she looked like her, Mia apologized to her.

Many believe she didn’t have to since it’s not her fault, nor the young woman who was objectified and sexualized.

“I can’t wear my glasses because the high school boys keep saying I look like Mia Khalifa with them, and it makes me uncomfortable.” — @oreo_mlkshake

Mia Khalifa has pivoted to become a girl’s girl influencer. She does make it look easy. One thing that Mia knows about what works on social media is authenticity.

And she had learned how to open up with her fans, now mostly women who empathize with her life experiences, from disordered eating to dissociative trauma.

With her social media capital, she has transcended mainstream entertainment, and recently appeared in the hit ‘MAMIII’ Video by Becky G & Karol G, she was cast opposite ‘Euphoria’ star Angus Cloud.

The song MAMIII became №1 on Billboard’s Hot Latin Songs chart.

Final words

Digital permanence, they say what’s on the Internet stays on the Internet forever. It could be true. But your past should never define who you are today.

Source: Instagram Mia Khalifa

Mia Khalifa admittedly made a big mistake when she entered the adult entertainment industry at the age of 21, an error in judgment.

If she let her past define her, she wouldn’t be the star she is today. She uses her social media influence to bring to public attention issues that are close to her heart, like when she tweeted in support of farmers’ protests in India.

Yes, she is often criticized for voicing her opinions on social media like when she shared this video clip of a Russian ambassador being drenched in blood-like red paint.

She is often referenced as the former porn star it’s like a scarlet letter society wants her to wear for the rest of her life.

She once co-hosted a sports talk show with former NBA star Gilbert Arenas, but the male fans wouldn't let her forget about her past, the toxic male energy was too much for her that she had to quit the show, never mind if she was making $10,000 a month from the show.

Today, she has everything. After being married and divorced twice, she met a man who loves her, Puerto Rican singer Jhayco.

She says she is at peace with herself. She couldn’t have said it better at the end of her interview.

Like, yeah, all of these (bad) things wouldn’t have happened. But also, I wouldn’t be where I am right now.”

Lastly, if you are looking for nudity on her OnlyFans account, please respect the rebrand.

Thank you for reading.

Sources:

How Mia Khalifa found community and consent on OnlyFans

Please Respect Mia Khalifa’s Rebrand

Do you want more OnlyFans stories? Check these out.

Man Found Hiding in the Attic of an OnlyFans Model — Free reading!

👉Claim your offer.

If you enjoyed this article, please consider joining Medium by clicking on this link. I may earn a little commission to buy myself a decent cup of coffee. Thank you.

Sexuality
Social Media
Mia Khalifa
Money
Society
Recommended from ReadMedium