Last active
April 8, 2024 13:23
-
-
Save ruxo/7ac926bab7e76c9d971e8edcaa6bb447 to your computer and use it in GitHub Desktop.
Show how to use LanguageExt's Eff(ect) with memo to cache value.Note that `LanguageExt.Core` library is needed for running.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using LanguageExt; | |
using static LanguageExt.Prelude; | |
public static class Program { | |
public static void Main (string[] args) { | |
var program = | |
from v1 in Load | |
from _1 in eff(() => Console.WriteLine($"1st value = {v1}")) | |
from v2 in Load | |
from _2 in eff(() => Console.WriteLine($"2st value = {v2}")) | |
select unit; | |
program.RunUnit(); | |
} | |
static int LoadSomething(){ | |
Console.WriteLine("Load!"); | |
return 123; | |
} | |
// try remove memo for comparision | |
static Eff<int> Load = Eff(memo(LoadSomething)); | |
static Eff<Unit> eff(Action a) => | |
Eff(() => { | |
a(); | |
return unit; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment