r/functionalprogramming • u/GiraffeOk5274 • Feb 13 '24
FP Functional programming in typescript
https://github.com/gcanti/fp-tsAnyone used this library fp-ts in typescript. would like to hear feedbacks and also anything to get started with it.
15
Upvotes
4
u/msrobinson42 Feb 13 '24
I think fp-ts creator joined forces with effect-ts and effect-ts has much better docs. I recommend trying out effect-ts instead for your typescript functional programming.
4
u/Adventurous-Cod-287 Feb 14 '24
Yes. Used it extensively along with the rest of the adjacent libs(io-ts, monocle, brand) on a large project for two years.
This library stack is phenomenal. The learning curve is fairly steep. I did not have previous experience with fp at this level so it was pretty challenging to get started given the very limited documentation.
To me, practical functional programming is about allowing me to structure my code into small functions that can provably never fail(expressed with the type system) and then also accept and emit a fixed number of type shapes. Then those functions can be combined together into easily comprehendible unidirectional pipelines in infinite ways to solve any computational problem, including modeling changing state, IO, etc.
I know I'm preaching to the choir here, but in my experience that absolutely changes your day to day experience as an engineer making entire classes of hard to debug or easy to miss bugs nonexistent and distilling your daily work to solving an infinite number of small satisfactory “algebra” type problems that are then effortlessly composed to provide the guaranteed and correct final solution. This is super worth it.
However, accomplishing this in plain typescript would require writing disturbing amounts of boilerplate and difficult type signatures on daily basis. FP-TS is essentially that boilerplate all figured out and wrapped into a neat and expressive library. In addition to that, it provides a great standard library of functions to deal with all common data structures in predictable ways that also very neatly compose together.
Unfortunately, to reap the full benefits and “see the light” l, I think it requires fully going in and adopting a coding style that is somewhat at odds with many common TS code practices.
4
u/pm_me_ur_happy_traiI Feb 13 '24
I haven't used fp-ts, but I will say that typescript lends isitself to fp quite well.
2
u/nadameu Feb 14 '24
This YouTube channel has a few introduction videos for fp-ts.
2
u/[deleted] Feb 13 '24
[removed] — view removed comment