Skip to content

Commit 357f53c

Browse files
committed
Update README.md with new Computation Expression example
1 parent c3d0743 commit 357f53c

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,52 @@ Slug generated from "Test | 🤡" with custom map: "test_or_clown"
7373

7474
```
7575

76+
## Slug Custom Computation Expression
77+
78+
It is possible to use the custom Computation Expression in order to define your custom slugify function.
79+
80+
Here a simple example:
81+
82+
``` fsharp
83+
open FSlugify.Builder
84+
85+
[<EntryPoint>]
86+
let main argv =
87+
printfn "This example shows how to use the custom Slug Computation Expression!\n"
88+
89+
let customSlugify = slug {
90+
separator '@'
91+
lowercase false
92+
custom_map ("|", " or ")
93+
custom_map ("&", " and ")
94+
custom_map ("⏳", " hourglass ")
95+
custom_map ("🤡", " clown")
96+
}
97+
98+
customSlugify "Test | Case"
99+
|> printfn "Slug generated from \"Test | Case\": \"%s\"\n"
100+
101+
customSlugify " Test & ⏳ "
102+
|> printfn "Slug generated from \" Test & ⏳ \": \"%s\"\n"
103+
104+
customSlugify "HI 🤡!!!"
105+
|> printfn "Slug generated from \"HI 🤡!!!\": \"%s\"\n"
106+
0
107+
108+
```
109+
This program will output the following text:
110+
111+
``` shell
112+
This example shows how to use the custom Slug Computation Expression!
113+
114+
Slug generated from "Test | Case": "Test@or@Case"
115+
116+
Slug generated from " Test & ⏳ ": "Test@and@hourglass"
117+
118+
Slug generated from "HI 🤡!!!": "HI@clown"
119+
120+
```
121+
76122
## FSlugify.Adapter
77123

78124
Although the library is usable as it is in a C# project (as it shown in the C# sample), for a better usability (both in syntax and usability) it's preferred to use the library [FSlugify.Adapter](https://github.com/galassie/fslugify-adapter).

samples/FSharp.ComputationExpression/Program.fs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
open FSlugify.SlugGenerator
2-
open FSlugify.Builder
1+
open FSlugify.Builder
32

43
[<EntryPoint>]
54
let main argv =
@@ -15,11 +14,11 @@ let main argv =
1514
}
1615

1716
customSlugify "Test | Case"
18-
|>printfn "Slug generated from \"Test | Case\": \"%s\"\n"
17+
|> printfn "Slug generated from \"Test | Case\": \"%s\"\n"
1918

2019
customSlugify " Test & ⏳ "
21-
|>printfn "Slug generated from \" Test & ⏳ \": \"%s\"\n"
20+
|> printfn "Slug generated from \" Test & ⏳ \": \"%s\"\n"
2221

2322
customSlugify "HI 🤡!!!"
24-
|>printfn "Slug generated from \"HI 🤡!!!\": \"%s\"\n"
23+
|> printfn "Slug generated from \"HI 🤡!!!\": \"%s\"\n"
2524
0

0 commit comments

Comments
 (0)