Instantly share code, notes, and snippets.

View FP2TheMax.fs
open System
type Eff<'Ctx, 'T> = 'Ctx -> 'T
type EffBuilder() =
member __.Return x : Eff<'Ctx,'T> =
fun _ -> x
member __.Bind(f : Eff<'Ctx, 'T>, g : 'T -> Eff<'Ctx, 'S>) : Eff<'Ctx, 'S> =
fun c -> g (f c) c
member __.Zero() : Eff<'Ctx, unit> =
View safetraversal.fs
let rec bfs2robust (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq =
let single = seq [node]
match fanout tree node with
| e when e = Seq.empty -> single
| s -> Seq.fold (fun acc item ->
bfs2robust fanout (tree |> Map.remove node) item
|> Seq.append acc) single s |> Seq.distinct
View gotrees.fs
let rec bfs2 (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq =
let single = seq [node]
match fanout tree node with
| e when e = Seq.empty -> single
| s -> Seq.fold (fun acc item ->
bfs2 fanout tree item
|> Seq.append acc) single s
View BindableTextBlock.cs
public class BindableTextBlock : TextBlock
{
public ObservableCollection<Inline> InlineList
{
get { return (ObservableCollection<Inline>)GetValue(InlineListProperty); }
set { SetValue(InlineListProperty, value); }
}
public static readonly DependencyProperty InlineListProperty =
DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged));
View view_v2.xaml
<DataGrid Grid.Column="2" ItemsSource="{Binding SelPayment.eur_invoices}" IsReadOnly="True" AutoGenerateColumns="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" >
<DataGrid.Columns>
<DataGridTextColumn Header="Buy/Sell" Binding="{Binding buysell}" />
<DataGridTextColumn Header="Cpty Name" Binding="{Binding CptyName}" />
<DataGridTextColumn Header="Invoice Nr" Binding="{Binding InvoiceNr}" />
<DataGridTextColumn Header="Amount" Binding="{Binding amount, StringFormat=N}" />
<DataGridTextColumn Header="Curr" Binding="{Binding curr}" />
<DataGridTextColumn Header="Msg" Binding="{Binding ui.msg}" />
</DataGrid.Columns>
View model_v2.fs
type Back2UI() =
inherit SimpleViewModelBase()
let mutable _msg = ""
member this.msg
with get() = _msg
and set value =
_msg <- value
this.OnPropertyChanged(<@ this.msg @>)
type ActivePassive = Active | Passive
View view.xaml
<DataGrid Grid.Column="2" ItemsSource="{Binding SelPayment.eur_invoices}" IsReadOnly="True"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" >
View model.fs
// business model
type Invoice = { CptyName: string; CptyNum: int; InvoiceNr: string; amount : decimal; curr: string; buysell: ActivePassive}
// array extraction from Excel with type provider
let ActiveInvoice =
ActiveInvoiceExcel.Data
|> Seq.map ( fun line -> { InvoiceNr = line.``Numero documento``; ... })
|> Seq.toArray
View Differ.fs
type DifferenceType<'TKey, 'T> =
| Added of 'TKey * 'T
| Removed of 'TKey * 'T
| Modified of 'TKey * 'T * 'T * seq<string * (string * string)> with
member this.Key =
match this with
| Added (key, _)
| Removed (key, _)
| Modified (key, _, _, _) -> key
View CSharpVsScalaAsync
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;