DEV Community

Cover image for Introduction to composable optics with monocle-ts

Introduction to composable optics with monocle-ts

Kimmo Sääskilahti on February 16, 2020

Optics are a functional programming toolbox for zooming into nested data structures. They are designed for composability, allowing you to create co...
Collapse
 
mikesol profile image
Mike Solomon

Really cool stuff! One way that I've blended io-ts and monole-ts together is the use of the .is function in io-ts to replicate pattern matching in Haskell or OCaml. That helps especially in Prisms. So, for example...

new Prism<string | integer, string>(a => t.string.is(a) ? some(a) : none, s => s)
Enter fullscreen mode Exit fullscreen mode

Here, is is a primitive type of pattern matching that does the job both at runtime and at compile time (this is compile safe in typescript).

Collapse
 
gabrielfallen profile image
Alexander Chichigin

Cool post! These are indeed cool TS libraries, thanks for spreading the word!

But oh boy, how syntactically awkward is that compared to Haskell... 😃