DEV Community

Discussion on: Rise of the Reducer

Collapse
 
shimmer profile image
Brian Berns • Edited

Just want to mention that this comes from the concept of a fold/reduce in functional programming. For example, in F#, you could process a stream of messages using fold:

let msgs = [ NextTurn; NextTurn; Restart; NextTurn; NextTurn ]
let initialModel = init ()
let finalModel =
    Seq.fold
        (fun model msg -> update msg model)
        initialModel
        msgs
printfn "%A" finalModel
Enter fullscreen mode Exit fullscreen mode
Collapse
 
integerman profile image
Matt Eland

Love it. I think you can put fs after the triple apostrophes to get F# syntax highlighting there.

And yes, I'm doing a ton of F# programming recently, which inspired the post on reducers at large.

Collapse
 
shimmer profile image
Brian Berns

Thanks. I actually had to use “fsharp” to trigger syntax highlighting.