2 ms·
The white lie is that in functional programming a function only takes a single argument and uses currying to mimic multiple arguments. Like this in JS: let
by williamcotton 2y ago
The white lie is that in functional programming a function only takes a single argument and uses currying to mimic multiple arguments.
Like this in JS:
let f = (x) => (y) => x * y;
let p = f(2)(3);
Is this in F#:
let f x y = x * y
let p = f 2 3
A ResultWriter is just a wrapper type that takes a tuple of a Result and a list of log messages.
The side effects are you can write imperative code that works with normal values but does exception handling and log messaging behind the scenes and without it cluttering the task at hand.
So you write some functions that return either Success wrapping a value with some good news log message or an Error with some bad news log message. Then with a bind function or especially with a computation expression in F# you can use those functions without dealing with the exceptions and log messages until after you’ve completed all of the steps.
Unless you’re using a language that supports this kind of monad design pattern it won’t really make any sense!