Friday, December 1, 2023

Reactive Programming - Convert List[Mono[T]] to Mono[List[T]]

Hello world,

It's been a while, but I'm finally get back into a new groove with programming. My hope for the new year (2024) is to write more on my lessons transitioning to reactive programming.

First, what is different between Reactive Programming vs Functional Programming?

I think this author's article does a splendid job in explaining the difference.

Also, what is different between Reactive Programming vs Imperative Programming?

This article is decent but I think JavaScript is the true language to consider the need for reactive programming due to the ability to process data without order (non-sequentially).

Okay, for now, let's dive into a challenge I had this morning (and I'll need to back track throughout next year). My issue this morning dealt with my need to:

Convert a List<Mono<T>> to a Mono<List<T>

Because, my response to the client needs to be in a Mono<T>; not List<T>.

Since I couldn't figure this out on my on with Mono.map(), Mono.flatMap() and Flux.fromIterable(), I used ChatGPT. You can see my exact question and ChatGPT's solution at the bottom of my conversation here.


Solution (from ChatGPT)

---

To convert a `List<Mono<T>>` to a `Mono<List<T>>` in a reactive programming context using Project Reactor in Java, you can use the `Flux.concat` operator along with `collectList`. Here's an example:


import reactor.core.publisher.Flux;

import reactor.core.publisher.Mono;


import java.util.List;


public class MonoListConversion {


    public static void main(String[] args) {

        // Your original List<Mono<T>>

        List<Mono<String>> monoList = getOriginalMonoList();


        // Convert List<Mono<T>> into Mono<List<T>>

        Mono<List<String>> resultListMono = Flux.concat(monoList).collectList();


        // Now, you have Mono<List<T>> as the result

        resultListMono.subscribe(System.out::println);

    }


    private static List<Mono<String>> getOriginalMonoList() {

        // Your logic to obtain List<Mono<T>>

        // For demonstration purposes, let's create a simple example

        Mono<String> mono1 = Mono.just("Value 1");

        Mono<String> mono2 = Mono.just("Value 2");

        return List.of(mono1, mono2);

    }

}


In this example, `Flux.concat` is used to concatenate the values emitted by the `Mono` instances into a single `Flux`. Then, `collectList` is used to collect the values emitted by the `Flux` into a `Mono<List>>`.

This approach ensures that the values emitted by the `Mono` instances are processed sequentially, maintaining the order of the original list. If the order is not important, you can also use `Flux.merge` instead of `Flux.concat` for concurrent processing.

---


Wednesday, August 9, 2023

Using AI for hacks, attacks

Thanks to IBM researchers, we now have valid proof of the wrongful uses of AI in action. Another reason for AI companies to implement safeguards for societal health.

https://www.axios.com/2023/08/08/ibm-researchers-trick-chatgpt-hacking

Tuesday, August 8, 2023

Nuclear Engines by 2030?

DARPA and NASA aim to test Nuclear Rocket by 2026

"The engine would drastically shorten trips to the moon and Mars."
https://spectrum.ieee.org/nuclear-thermal-rocket

This project, if successful, will launch our way of living into a whole 'notha world. Combined with flying vehicles like EVTOLs, mobility will officially allow people to go have breakfast in the United States, work in Japan, have lunch in Italy, take a training in India, have dinner in Colombia, and then enjoy a restful night in Botswana. All in one day. In addition, people can literally work anywhere whether online or in-person.

Friday, June 23, 2023

Good Tips on GitHub Copilot

https://github.blog/2023-06-20-how-to-write-better-prompts-for-github-copilot/

That's it folks! Enjoy!

Oh, also check this out:
https://github.blog/2023-07-17-prompt-engineering-guide-generative-ai-llms/

Thursday, May 18, 2023

Monday, February 6, 2023

ChatGPT, OpenAI, Anthropic?

I wrote about Notion AI a couple months ago. Since then, a lot has happened in the world of AI. OpenAI took headlines with ChatGPT, Microsoft laid off thousands to invest millions into OpenAI, and Google followed suit with also laying off thousands to invest millions into Anthropic AI and announces Bard. Why hasn't such corporations used those millions to invest in their employees - is a question that simply repeats history. For my fellow techmates, beware of the corporate checkmates and steer your own career.

P.S. And then there's Poe, from Quora.

https://openai.com/
https://openai.com/blog/chatgpt/
https://www.anthropic.com/
https://blog.google/technology/ai/bard-google-ai-search-updates/
https://techcrunch.com/2023/02/06/quora-opens-its-new-ai-chatbot-app-poe-to-the-general-public/

Thursday, January 26, 2023

neo.mjs - a new approach to frontend development

This new front-end development approach with this new framework is very interesting. I wonder how this compares to ReactJS.

Monday, January 23, 2023

Globalization Outlook & its Economy


I think this goes for all Western countries and it's a good outlook to consider.
"And Europe is failing to recognize the economic potential and necessity of organized migration while ignoring its economic dependence on foreign workers."
https://youtu.be/gIYaSEwoblY?t=2405

Watch full context of DW's Globalization two-part documentary:
https://www.youtube.com/watch?v=yoZiTCz_wYA (part 1: "Winners & losers in world trade")
https://www.youtube.com/watch?v=gIYaSEwoblY (part 2: "Profits over People")

In addition, China will not remain as the economic power that it was - primarily due to the lack of consideration for the People's Leadership. Basically, the rise of China happened under a caring prime minister; not a limitless term one. For more context, read this article.

Does anyone remember when many goods were manufactured in Mexico? What happened?

Sunday, January 22, 2023

PhD programs vs Start-ups

This is a really good article critiquing the PhD worldwide. 

In addition, the pressure continues to mount up as capitalism invests in start-ups like research incubators. These investments bypass academia which further decreases the value of "higher education". Therefore, do students even need a college degree? Should a high school graduate consider working in a start-up than attending college? Perhaps Bill Gates, Mark Zuckerberg, and Kanye West knew the secret key to a successful career by attending college to eventually drop out as they launched their own careers as promising entrepreneurs?

Friday, January 20, 2023

Open Metaverse Foundation & Web3

This could be the start of a new tech era.

It's one thing to apply blockchain technology to an existing infrastructure where large corporations could still centralize power due to exchanges being trusted by the public with certified brand names. But, what if the public could trust smaller entities? And how does a small entity quickly get into the game of trusted exchanges among large corporations without looking like a troll, a bot, or a hacker?

There has to be more tools available and a new information infrastructure to certify these tools. I think the new OMF is what will usher in this new digital era and establish blockchain technology, AI, and VR/AR. And, the quicker we can launch quantum computing, the quicker OMF will rise.

P.S. Interestingly, one noticeable sponsor is Meta.

Monday, January 2, 2023

Pony IO

I just heard about this programming language which has built-in features that I really like, such as no locks and no nulls.

I'll need to play with it to truly understand its uniqueness and value.


Article on Skills In-Demand for Backend Developers

It's always important to stay up-to-date with the job market for software development. As human interfaces may change, one assurance is the calls for data to the backend programs will always be important and need improvements. It's always quicker to throw up a UI/UX, but it's always important to deliver a reliable backend. Else, the frontend just ends up being a nice prototype.
That's why I like this article and am sharing it.
https://www.dice.com/career-advice/back-end-developer-skills-you-need-to-know