1 people like it.
Like the snippet!
Implement a suppression list
Take a sequence and exclude values from it based on another 'suppression list' sequence.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
|
module Suppress
// Returns a sequence which consists of the items from 'values' for which
// no item in 'unwanted' gives true when passed to function (f valueItem unwantedItem).
let suppressBy (f : 'T -> 'U -> bool) (values : seq<'T>) (unwanted : seq<'U>) =
values
|> Seq.filter (fun v -> unwanted |> Seq.exists (fun u -> f v u) |> not)
// [0; 1; 2; 5; 6; 7; 8; 9]
let example =
suppressBy (=) [0..9] [3; 4] |> List.ofSeq
type Prospect = { name : string; phoneNumber: string }
type TPSRecord = { phoneNumber: string }
let prospects = [ {name = "A Smith"; phoneNumber = "01234 56789"}
{name = "B Smith"; phoneNumber = "01234 56710"}
{name = "C Smith"; phoneNumber = "01234 56711"} ]
let tpsData = [ {phoneNumber = "01234 56710"}
{phoneNumber = "01234 56712"} ]
// [{name = "A Smith"; phoneNumber = "01234 56789";}
// {name = "C Smith"; phoneNumber = "01234 56711";}]
let doTpsSuppression =
prospects |> suppressBy (fun p s -> p.phoneNumber = s.phoneNumber) tpsData
|> List.ofSeq
|
module Suppress
val suppressBy : f:('T -> 'U -> bool) -> values:seq<'T> -> unwanted:seq<'U> -> seq<'T>
Full name: Suppress.suppressBy
val f : ('T -> 'U -> bool)
type bool = System.Boolean
Full name: Microsoft.FSharp.Core.bool
val values : seq<'T>
Multiple items
val seq : sequence:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Core.Operators.seq
--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
Full name: Microsoft.FSharp.Collections.seq<_>
val unwanted : seq<'U>
module Seq
from Microsoft.FSharp.Collections
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.filter
val v : 'T
val exists : predicate:('T -> bool) -> source:seq<'T> -> bool
Full name: Microsoft.FSharp.Collections.Seq.exists
val u : 'U
val not : value:bool -> bool
Full name: Microsoft.FSharp.Core.Operators.not
val example : int list
Full name: Suppress.example
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val ofSeq : source:seq<'T> -> 'T list
Full name: Microsoft.FSharp.Collections.List.ofSeq
type Prospect =
{name: string;
phoneNumber: string;}
Full name: Suppress.Prospect
Prospect.name: string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Prospect.phoneNumber: string
type TPSRecord =
{phoneNumber: string;}
Full name: Suppress.TPSRecord
TPSRecord.phoneNumber: string
val prospects : Prospect list
Full name: Suppress.prospects
val tpsData : TPSRecord list
Full name: Suppress.tpsData
val doTpsSuppression : TPSRecord list
Full name: Suppress.doTpsSuppression
val p : TPSRecord
val s : Prospect
More information