2 people like it.

Replace Elements

Replace elements

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
open FsUnit
open Xunit

[<Fact>]
let transform() =
    let inline replace1 list a b = list |> Seq.map (fun x -> if x = a then b else x)
    let inline replace2 list func = list |> Seq.map func

    replace1 "hello, how are you?" 'e' 'a' |> should equal "hallo, how ara you?"
    replace1 [1;2;3;4;5;4;3;2;1] 3 9 |> should equal   [1;2;9;4;5;4;9;2;1]

    replace2 "hello, how are you?" (fun x -> if x = 'e' then 'a' else x) |> should equal "hallo, how ara you?"
    replace2 [1;2;3;4;5;4;3;2;1] (fun x -> if x = 3 then 9 else x) |> should equal  [1;2;9;4;5;4;9;2;1]
namespace FsUnit
val transform : unit -> unit

Full name: Script.transform
val replace1 : (seq<'a> -> 'a -> 'a -> seq<'a>) (requires equality)
Multiple items
val list : seq<'a> (requires equality)

--------------------
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val a : 'a (requires equality)
val b : 'a (requires equality)
module Seq

from Microsoft.FSharp.Collections
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val x : 'a (requires equality)
val replace2 : (seq<'a> -> ('a -> 'b) -> seq<'b>)
Multiple items
val list : seq<'a>

--------------------
type 'T list = List<'T>

Full name: Microsoft.FSharp.Collections.list<_>
val func : ('a -> 'b)
val should : f:('a -> #NUnit.Framework.Constraints.Constraint) -> x:'a -> y:obj -> unit

Full name: FsUnit.TopLevelOperators.should
val equal : x:'a -> EqualsConstraint

Full name: FsUnit.TopLevelOperators.equal
val x : char
val x : int
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/qV
Posted:9 years ago
Author:Pitch Rock
Tags: replace