Among functional coding libraries, fp-ts gained popularity by focusing on functional mapping and monads, but it has evolved into a framework by being integrated into Effect.
Unlike existing libraries, Effect operates like a framework, and users need to possess relevant knowledge to utilize Effect objects.
Effect utilizes objects encapsulated by Effect, similar to RxJs's Observable, and it is anticipated to establish a new standard in the Node.js industry.
Functional coding has been quite trendy over the past few years.
While object-oriented programming provides structure,
functional coding has contributed to the conciseness of detailed code.
Of course, the popularity of functional coding tends to follow a cyclical pattern, recurring every few years.
Driven by this trend, various libraries have begun to emerge.
While the previous fp-ts was more library-like, this new Effect leaned more towards a framework.
To utilize Effect, a foundational understanding of Effect itself was necessary.
NestJs and NextJs require a similar level of comprehension for their respective uses.
While libraries can be readily adopted if their APIs are well-exposed, frameworks necessitate a deeper understanding of the underlying package.
import{Effect,Console}from"effect"let i =1const expensiveTask =Effect.promise(()=>{console.log("expensive task...")returnnewPromise((resolve)=>{setTimeout(()=>{resolve(result ${i++})},100)});})const program =Effect.gen(function*(){console.log("non-cached version:")yield* expensiveTask.pipe(Effect.andThen(Console.log))yield* expensiveTask.pipe(Effect.andThen(Console.log))console.log("cached version:")const cached =yield*Effect.cached(expensiveTask)yield* cached.pipe(Effect.andThen(Console.log))yield* cached.pipe(Effect.andThen(Console.log))})Effect.runFork(program)/*
Output:
non-cached version:
expensive task...
result 1
expensive task...
result 2
cached version:
expensive task...
result 3
result 3
*/
This Effect instead of being wrapped in Observables like RxJs, utilizes Effect-wrapped objects that are passed around,
almost like the async keyword, spreading its influence.
To use Effect objects, the functions that utilize them also need to become Effect objects.
Similar to program in the code above.
While there are entry point functions available, they lack a certain appeal.
In any case, the structure and neatness of Effect in its role as a framework suggests the potential for a new wave and standard in the Node.js community, which I anticipate with excitement.