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
type dlist<'a> = ('a list -> 'a list) list | |
let dmap f (xs: dlist<'a>) : dlist<'a> = List.map f :: xs | |
let drun (xs: dlist<'a>) = List.foldBack (<|) xs [] | |
let inline cons x xs = x :: xs | |
let drange from count = | |
let rec loop curr acc : dlist<int> = |
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
#r "nuget: FSharp.Interop.Dynamic" | |
open System | |
open System.Collections | |
open System.Linq.Expressions | |
open System.Linq | |
open FSharp.Interop.Dynamic | |
// query.Select(selector) | |
let select (selector: LambdaExpression) (query: IQueryable) : IQueryable = |
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
#r "nuget:AWSSDK.SecurityToken" | |
open Amazon | |
open Amazon.Runtime.CredentialManagement | |
open Amazon.SecurityToken | |
open Amazon.SecurityToken.Model | |
let awsCredentials profile = | |
let chain = CredentialProfileStoreChain() | |
match chain.TryGetAWSCredentials profile with |
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.Text.Json; | |
var value = new { name = default(string)! }; | |
//method #1 | |
value = (dynamic)JsonSerializer.Deserialize("""{ "name": "xyz" }""", value.GetType())!; | |
Console.WriteLine(value); | |
//method #1 |
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.Linq; | |
using System.Linq.Expressions; | |
static class _ | |
{ | |
static void Deconstruct(this BinaryExpression x, | |
out ExpressionType type, | |
out Expression left, | |
out Expression right) |
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
type IRef = | |
abstract member Ref: unit -> byref<int> | |
type C() = | |
let mutable num = 10 | |
member _.Get() = num | |
member _.Ref() = &num | |
interface IRef with | |
member this.Ref() = &this.Ref() |
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
open System.Numerics | |
module NumericLiteralG = | |
let inline FromZero () : #INumber<'a> = 'a.Zero | |
let inline FromOne () : #INumber<'a> = 'a.One | |
let inline FromInt32 (number: int) : #INumber<'a> = 'a.CreateChecked(number) | |
let (*) x y : #IMultiplyOperators<'a, 'a, 'a> = 'a.op_Multiply(x, y) | |
let (/) x y : #IDivisionOperators<'a, 'a, 'a> = 'a.op_Division(x, y) |
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
### Nullable Reference Types | |
https://devblogs.microsoft.com/dotnet/nullable-reference-types-in-csharp/ | |
https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#non-nullable-properties-and-initialization | |
The purpose of nullable warnings is to minimize the chance that your application throws a `System.NullReferenceException` when run. | |
To enable Nullable Reference Types for all code in a project, you can add the following to its `.csproj` file: |
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.Diagnostics.CodeAnalysis; | |
using System; | |
static Result<Foo, Err> GetResult(bool isErr) | |
=> isErr ? Result.Ok(new Foo()) : Result.Error(new Err()); | |
Console.WriteLine(GetResult(true) switch | |
{ | |
{ Success: true, Value: var value } => value, | |
{ Success: false, Error: var error } => error, |
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
namespace Data.Model.Entities | |
{ | |
using System; | |
using System.Data.Entity.Core.Metadata.Edm; | |
using System.Data.Entity.Infrastructure; | |
using System.Data.Entity.ModelConfiguration.Conventions; | |
using System.Linq; | |
using System.Reflection; | |
public class CommentSplittingFixer : IStoreModelConvention<EdmModel> |
NewerOlder