This file contains 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
var freeVar = 100; | |
Func<string, int> length = x => x.Length + freeVar; | |
var f = new Fun<string, int>(length); | |
var r = f.Invoke("Hello"); | |
Console.WriteLine(r); // 105 | |
public readonly unsafe struct Fun<A> | |
{ | |
readonly object? self; |
This file contains 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.Numerics; | |
using LanguageExt; | |
using LanguageExt.Common; | |
using LanguageExt.Traits; | |
using static LanguageExt.Prelude; | |
namespace ValidationExamples; | |
// Credit card number |
This file contains 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
module Validation = | |
open LanguageExt | |
let successValue (ma : Validation<'f, 'a>) : 'a = | |
ma.IfFail(fun () -> failwith "Validation monad is in a Fail state") | |
let apply (mf : Validation<'f, 'a -> 'b>) (ma : Validation<'f, 'a>) : Validation<'f, 'b> = | |
mf.Disjunction(ma) | |
.Map(fun _ -> (successValue mf) (successValue ma)) | |
This file contains 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
string? name = "Paul"; | |
string? noName = null; | |
// Only says hello if not null | |
var helloName = name.Map(n => $"Hello, {name}"); // "Hello, Paul" | |
var noHelloName = noName.Map(n => $"Hello, {name}"); // null | |
// Nullable strings ... | |
string? sx = "Hello"; | |
string? sy = "World"; |
This file contains 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; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var xs = new[] {"one", " ", "two", " ", "three"}; | |
var ys = new[] {1, 2, 3}; |
This file contains 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; | |
namespace RiderCandidates | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains 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 System.Diagnostics.Contracts; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.ExceptionServices; | |
using LanguageExt.Common; | |
using LanguageExt.DataTypes.Serialisation; | |
using static LanguageExt.Prelude; | |
namespace LanguageExt | |
{ |
This file contains 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 Echo; | |
using LanguageExt; | |
using static LanguageExt.Prelude; | |
using static Echo.Process; | |
using System; | |
namespace StackOverflow2 | |
{ | |
class Program | |
{ |
This file contains 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; | |
namespace StackOverflow1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains 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 LanguageExt.TypeClasses; | |
using System.Diagnostics.Contracts; | |
namespace Defunctionalisation | |
{ | |
class Program | |
{ | |
static void Main(string[] args) |
NewerOlder