-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChapter_05_ex_1.fs
More file actions
25 lines (23 loc) · 712 Bytes
/
Chapter_05_ex_1.fs
File metadata and controls
25 lines (23 loc) · 712 Bytes
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
module Chapter_05_ex_1
#if INTERACTIVE
#r "packages/Unquote.2.2.2/lib/net40/unquote.dll"
#r "packages/NUnit.2.6.2/lib/nunit.framework.dll"
#endif
open System
open NUnit.Framework
open Swensen.Unquote
// 5.1
// List.filter: ('a -> bool) -> 'a list -> 'a list
let foldedFilter predicate items =
List.foldBack (fun item state ->
match predicate item with
| false -> state
| true -> item::state
)
items
[]
[<TestFixture>]
type ``Chapter 05 exercise 1 Tests``() =
[<Test>]
member x.``5.1 foldedFilter``() =
test <@ (foldedFilter (fun x -> x > 0) [-2;-1;0;1;2]) = [1;2] @>