Skip to content

Commit 8a788b5

Browse files
authored
Add standard usage documentation and examples
1 parent aee87f5 commit 8a788b5

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ The goal of this project is to expose selected F# classes to C#. There are some
66

77
---
88

9+
## Usage
10+
11+
```csharp
12+
using FSharpPlusCSharp;
13+
using Microsoft.FSharp.Core;
14+
15+
var a = 5.Some();
16+
var b = 6.Some();
17+
var sum = from x in a
18+
from y in b
19+
select x + y; // Some 11
20+
21+
var result = sum.ToResult("missing value");
22+
```
23+
24+
Public APIs also include XML documentation comments so usage is rendered by standard .NET documentation tooling (for example IntelliSense).
25+
26+
---
27+
928
## Builds
1029

1130
MacOS/Linux | Windows

src/FSharpPlus.CSharp/Library.fs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ module internal Internals=
1212
open Internals
1313

1414
[<Extension>]
15+
/// <summary>
16+
/// Helpers for working with <c>FSharpOption&lt;T&gt;</c> from C#.
17+
/// </summary>
18+
/// <example>
19+
/// <code lang="csharp">
20+
/// var sum = from x in 5.Some()
21+
/// from y in 6.Some()
22+
/// select x + y; // Some 11
23+
/// </code>
24+
/// </example>
1525
type Options =
1626
static member Cast(o:obj) : 'a option =
1727
try
@@ -42,6 +52,9 @@ type Options =
4252
| _ -> Some v
4353

4454
[<Extension>]
55+
/// <summary>
56+
/// Creates <c>Some(value)</c> from C#.
57+
/// </summary>
4558
static member Some (a:'a) : 'a option = Option.Some a
4659

4760
[<Extension>]
@@ -158,6 +171,9 @@ type NumberParser(numberstyles: NumberStyles, cultureInfo: CultureInfo)=
158171

159172

160173
[<Extension>]
174+
/// <summary>
175+
/// Helpers for creating and matching F# <c>Choice</c> values from C#.
176+
/// </summary>
161177
type Choices =
162178

163179

@@ -197,6 +213,15 @@ type Choices =
197213
static member Create3Of3<'T1,'T2,'T3> (a: 'T3) : Choice<'T1,'T2,'T3> = Choice3Of3 a
198214

199215
[<Extension>]
216+
/// <summary>
217+
/// Helpers for working with F# <c>Result&lt;TOk, TError&gt;</c> from C#.
218+
/// </summary>
219+
/// <example>
220+
/// <code lang="csharp">
221+
/// var parsed = parser.TryParseInt("42").ToResult("invalid");
222+
/// var plusOne = parsed.Select(x => x + 1);
223+
/// </code>
224+
/// </example>
200225
type Results =
201226

202227
/// Attempts to cast an object.
@@ -236,7 +261,13 @@ type Results =
236261

237262
// constructors
238263

264+
/// <summary>
265+
/// Creates <c>Ok(value)</c>.
266+
/// </summary>
239267
static member Ok<'T1,'T2> (a: 'T1) : Result<'T1,'T2> = Ok a
268+
/// <summary>
269+
/// Creates <c>Error(value)</c>.
270+
/// </summary>
240271
static member Error<'T1,'T2> (b: 'T2) : Result<'T1,'T2> = Result.Error b
241272

242273

@@ -309,4 +340,3 @@ module Enums=
309340
let getValues<'t> ()=
310341
let values = System.Enum.GetValues (typeof<'t>)
311342
Enumerable.Cast<'t> values //Array.unbox
312-

0 commit comments

Comments
 (0)