Skip to content

Instantly share code, notes, and snippets.

View habib-sadullaev's full-sized avatar

habib sadullaev habib-sadullaev

  • Uzbekistan
View GitHub Profile
@habib-sadullaev
habib-sadullaev / deque.rkt
Last active February 22, 2019 10:31
sicp deque implementation
#lang racket
(define (make-deque) (mcons null null))
(define (front deque) (mcar deque))
(define (rear deque) (mcdr deque))
(define (set-front! deque item) (set-mcar! deque item))
(define (set-rear! deque item) (set-mcdr! deque item))
(define (empty? deque) (null? (front deque)))
open System.Runtime.InteropServices
type C1() = static member M([<Out>] arg: byref<C1>) = arg <- C1(); true // byref<C1> -> bool
type C2() = static member M(arg: byref<C2>) = arg <- C2(); true // byref<C2> -> bool
type C3() = static member M(arg: outref<C3>) = arg <- C3(); true // outref<C3> -> bool
C1.M // val it : unit -> bool * C1
C2.M // val it : C2 ref -> bool
C3.M // val it : unit -> bool * C2
//fsharplint:disable
type M<'a> = 'a option
let inline unit (x: 'a) : M<'a> = Some x
let inline (>>=) (x: M<'a>) (f: 'a -> M<'b>) : M<'b> =
x |> Option.bind f
type MonadBuilder() =
member _.Bind(mx: M<'a>, f: 'a -> M<'b>) = mx >>= f
member _.Return(x: 'a) = unit x
member _.ReturnFrom(mx : M<'a>) = mx
@habib-sadullaev
habib-sadullaev / typedQuotation.fsx
Last active August 19, 2020 08:23
strongly type expression splices
open FSharp.Quotations
open FSharp.Linq.RuntimeHelpers
open System.Linq
open System
type AST =
| StartsWith of string
| Contains of string
| EndsWith of string
@habib-sadullaev
habib-sadullaev / typed-expr-list-traverse
Created September 20, 2020 17:43
traverse Expr<'a> list into Expr<'a list>
let traverse (exprs: Expr<'a> list) =
let folder elem state = <@ %elem :: %state @>
let init = <@ [] @>
List.foldBack folder exprs init
[1..3] |> List.map (fun x -> <@ x @>) |> traverse
@habib-sadullaev
habib-sadullaev / buider
Last active November 6, 2020 06:31
option builder
open System
open System.Runtime.CompilerServices
[<Extension>]
type X =
[<Extension>]
static member Bind(_: OptionBuilder, v: 'a, f: 'a -> 'b option) =
match box v with
| null -> None
| :? string as v when String.IsNullOrEmpty v -> None
type Tuple = Tuple with
static member inline TupleMap (Tuple, (a, b)) = fun f -> (f a, f b)
static member inline TupleMap (Tuple, (a, b, c)) = fun f -> (f a, f b, f c)
static member inline TupleMap (Tuple, (a, b, c, d)) = fun f -> (f a, f b, f c, f d)
let inline mapTuple f x =
let inline map (a: ^a) (b : ^b) = ((^a or ^b) : (static member TupleMap : ^a * ^b -> ^t) (a, b))
map Tuple x f
mapTuple (fun x -> x * x + 1) (1, 2)
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>
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,
### 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: