Skip to content

Commit 006949c

Browse files
committed
Small refactoring of Prelude
1 parent 0052c65 commit 006949c

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/FSharpx.Extras/Prelude.fs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ module Prelude =
2525
/// Transforms an uncurried function to a triple-curried function.
2626
let inline curry3 f a b c = f (a, b, c)
2727

28+
/// Transforms an uncurried function to a triple-curried function.
29+
let inline uncurry3 f (a,b,c) = f a b c
30+
2831
/// Swap the elements of a pair.
2932
let inline swap (a,b) = (b,a)
3033

@@ -62,8 +65,14 @@ module Prelude =
6265
/// first character used in the symbol.
6366
let (^) = (<|)
6467

65-
// Bottom value
66-
let undefined<'T> : 'T = raise (NotImplementedException("result was implemented as undefined"))
68+
/// Bottom value
69+
let undefined<'T> : 'T = raise (NotImplementedException("result was implemented as undefined"))
70+
71+
/// Given a value, apply a function to it, ignore the result, then return the original value.
72+
let inline tee fn x = fn x |> ignore; x
73+
74+
/// Custom operator for `tee`: Given a value, apply a function to it, ignore the result, then return the original value.
75+
let inline (|>!) x fn = tee fn x
6776

6877
let inline toOption x = match x with
6978
| true, v -> Some v
@@ -75,19 +84,19 @@ module Prelude =
7584
static member parse =
7685
tryWith bool.TryParse
7786

78-
type SByte with
87+
type Byte with
7988
static member parseWithOptions style provider x =
80-
SByte.TryParse(x, style, provider) |> toOption
89+
Byte.TryParse(x, style, provider) |> toOption
8190

8291
static member parse x =
83-
SByte.parseWithOptions NumberStyles.Integer CultureInfo.InvariantCulture x
92+
Byte.parseWithOptions NumberStyles.Integer CultureInfo.InvariantCulture x
8493

85-
type Byte with
94+
type SByte with
8695
static member parseWithOptions style provider x =
87-
Byte.TryParse(x, style, provider) |> toOption
96+
SByte.TryParse(x, style, provider) |> toOption
8897

8998
static member parse x =
90-
Byte.parseWithOptions NumberStyles.Integer CultureInfo.InvariantCulture x
99+
SByte.parseWithOptions NumberStyles.Integer CultureInfo.InvariantCulture x
91100

92101
type UInt16 with
93102
static member parseWithOptions style provider x =
@@ -180,8 +189,8 @@ module Prelude =
180189

181190
// Active patterns
182191
let (|Boolean |_|) = Boolean.parse
183-
let (|SByte |_|) = SByte.parse
184192
let (|Byte |_|) = Byte.parse
193+
let (|SByte |_|) = SByte.parse
185194
let (|UInt16 |_|) = UInt16.parse
186195
let (|Int16 |_|) = Int16.parse
187196
let (|UInt32 |_|) = UInt32.parse
@@ -192,4 +201,4 @@ module Prelude =
192201
let (|Single |_|) = Single.parse
193202
let (|Double |_|) = Double.parse
194203
let (|DateTime |_|) = DateTime.parse
195-
let (|DateTimeOffset|_|) = DateTime.parse
204+
let (|DateTimeOffset|_|) = DateTimeOffset.parse

0 commit comments

Comments
 (0)