Skip to content
0:00 / 0:00

#statemonad#indexedstatemonad#scalaz

scale.bythebay.io: Vincent Marquez, Index your State for Safer Functional APIs

FunctionalTV

10K subscribers • 19 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • Presented by Vincent Marquez

Advanced. Deep dive for people who know the field.

869 views8 years ago2 recommendations

Programming languagesSoftware designScalaFunctional programmingAPI design

Vincent Marquez demonstrates how to use the IndexedState monad to enforce the correct ordering of API calls at compile time.

This talk video is a node in devreal.ai, the developer community graph. It connects to: Talk: Index your State for Safer Functional AP... — devreal.ai/t/171118-index-your-state-safer-functional-ap-sca… Interview: scale.bythebay.io: Vincent Marquez Interview — devreal.ai/t/2017m11-scale-bythebay-io-vincent-marquez-inter… Speaker: Vincent Marquez — devreal.ai/n/vincent-marquez Company: YTel — devreal.ai/c/ytel Event: Scale by the Bay — devreal.ai/e/171115-scale-by-the-bay-conference Explore these connections and related videos, photos, speakers’ blogs and podcasts, and other By the Bay networks. ----- What if there was a way to enforce the order of how people can call into your API? Most folks are familiar or have at least heard of the State monad, but here I wills how how an IndexedState is even more powerful and lets you craft APIs with even more compile time safety and constraints.

Why it's here

2 people recommend this

What people say. Recommended for learning how to enforce API call ordering and compile-time safety using the IndexedState monad.

Moments people linked to

u/volpegabrielin r/scala • Recommends

On “Multiple States with Conditions”

`StateS,A` is an alias for `StateTId,S,A` and `StateTF[_,S,A]` is an alias for `IndexedStateTF,S,S,A`. You might want to look into the latter one. Here's a quick talk explaining it. You don't need to know about CT to understand this. If you already understand `State` it shouldn't be difficult to understand `IndexedState`. Good luck!

u/runT1MEScalazin r/scala • Recommends

On “State Monad and Event Sourcing”

The State monad is generally for 'threading through' immutable states (in memory) in a monadic way, so it may not be applicable to what you're trying. However, you may get some benefit wiht your API by using an IndexedStateT. link to this video
1View on Reddit

u/ResidentAppointment5in r/scala • Mentions

On “Design by contract - Preconditions and Postconditions - I'm really amazed with Scala.”

You may find Stainless interesting. As others have pointed out, short of actual formal methods “outside the language,” if you will, Scala supports a programming style based on taking types and “abstract algebra” or “category theory” seriously. A catchphrase you’ll hear in the typed functional programming community is “make illegal states unrepresentable.” It refers to making types and functions operating on them as specific as is feasible with respect to the domain. It can be surprising how far you can go with this in Scala. For example, see Index Your State for Safer Functional APIs, which describes a powerful technique for modeling state machines with types in such a way that you can us…

u/paul_f_snivelyin r/scala • Mentions

On “CAS - is there any way to integrate Scala with CAS (in functional style)?”

Assuming CAS means this, it looks like the context is expected to be "you have a servlet you need to run in a servlet container and want to use CAS for authentication and authorization." So this doesn't help you, e.g. with http4s, which, while it supports running in servlet containers, does not rely on the servlet abstractions in constructing services. So it seems a lot like you'd need to roll your own support for the CAS protocol to accomplish what you're asking. In that case, I would strongly consider carefully specifying a "CAS algebra" and relying on `IndexedStateT` per Vincent Marquez to ensure the state transitions governed by the protocol are adhered to (meaning, your code won't co…