Skip to content
This repository
Browse code

Renamed satisfy to filter to match the common function name.

  • Loading branch information...
commit 7c44e482f1850c63b4f4bda4cadd0d248f04dab9 1 parent f0ab824
Ryan Riley authored March 05, 2011
12  src/Cashel.Tests/primitives_test.fs
@@ -6,6 +6,7 @@ open NUnit.Framework
6 6
 open FsUnit
7 7
 
8 8
 open Cashel
  9
+open Cashel.ListPrimitives
9 10
 
10 11
 [<Test>]
11 12
 let test_token () =
@@ -32,17 +33,14 @@ let test_listify_with_token () =
32 33
     listify token !!"test" |> should equal exp   
33 34
     
34 35
 [<Test>]
35  
-let test_satisy_simple_predicate () =
  36
+let test_filter_simple_predicate () =
36 37
     let exp = Some('t', !!"est")
37  
-    satisfy token (fun x -> x = 't') !!"test" |> should equal exp
  38
+    filter token (fun x -> x = 't') !!"test" |> should equal exp
38 39
 
39 40
 [<Test>]
40  
-let test_satisy_failure_predicate () =
41  
-    satisfy token (fun x -> x = 'e') !!"test" |> should equal None
  41
+let test_filter_failure_predicate () =
  42
+    filter token (fun x -> x = 'e') !!"test" |> should equal None
42 43
     
43  
-
44  
-open Cashel.ListPrimitives
45  
-
46 44
 [<Test>]
47 45
 let test_any_success_predicate () =
48 46
     any ['q'..'v'] !!"test" |> should equal (Some('t', !!"est"))
4  src/Cashel/CharListPrimitives.fs
... ...
@@ -1,6 +1,8 @@
1 1
 namespace Cashel
  2
+
2 3
 module CharListPrimitives =
3 4
     open Cashel
  5
+    open Cashel.ListPrimitives
4 6
 
5 7
     //-------------------------char list primitives-------------------------------------------
6 8
     
@@ -19,5 +21,5 @@ module CharListPrimitives =
19 21
     let letter = lowercase +++ uppercase
20 22
     let digit = any ['0'..'9']
21 23
     let digitval = digit >>= (fun d -> result (int d - int '0'))
22  
-    let space = satisfy token (System.Char.IsWhiteSpace)
  24
+    let space = filter token (System.Char.IsWhiteSpace)
23 25
     let skipSpace = repeat space |> forget
5  src/Cashel/ListPrimitives.fs
... ...
@@ -1,6 +1,5 @@
1 1
 namespace Cashel
2 2
 
3  
-[<AutoOpen>]
4 3
 module ListPrimitives =
5 4
     open Cashel
6 5
 
@@ -20,10 +19,10 @@ module ListPrimitives =
20 19
             | _ -> None
21 20
             
22 21
     ///any checks the value at the start of the input is in the list of tokens l
23  
-    let any l = satisfy token (fun x -> l |> List.exists (fun y -> x = y))
  22
+    let any l = filter token (fun x -> l |> List.exists (fun y -> x = y))
24 23
     
25 24
     ///matchToken checks the value at the start of the input matches the value v
26  
-    let matchToken v = satisfy token (fun x -> x = v)
  25
+    let matchToken v = filter token (fun x -> x = v)
27 26
     
28 27
     ///matchTokens recursively uses matchToken to check to see if a list of values l matches the start of the input
29 28
     let rec matchTokens l = 
8  src/Cashel/primitives.fs
@@ -6,7 +6,7 @@ module Primitives =
6 6
 
7 7
     //-------------------------Basic primitives----------------------------------------------------
8 8
     //These primitives make no assumption as to the basic types of the parser input or result types
9  
-    
  9
+ 
10 10
     ///Custom bind operator >>! binds parser p to result v, ignoring the return value of p
11 11
     let (>>!) p v = p >>= (fun _ -> result v)
12 12
     
@@ -21,10 +21,10 @@ module Primitives =
21 21
     
22 22
     ///listify turns the result of parsing function p into a single item list
23 23
     let listify p = p >>= (fun x -> result [x])
24  
-    
25  
-    ///satisfy checks the value returned from item against the predicate function p
26  
-    let satisfy parser pred =  parser >>= (fun x -> if pred x then result x else zero)
27 24
         
  25
+    ///filter checks the value returned from item against the predicate function f
  26
+    let filter p f = p >>= (fun x -> if f x then result x else zero)
  27
+    
28 28
     ///repeat looks for zero or more instances of the parsing function p
29 29
     let rec repeat p = (repeat1 p) +++ (result [])
30 30
     

0 notes on commit 7c44e48

Please sign in to comment.
Something went wrong with that request. Please try again.