Skip to content

Commit ac120e9

Browse files
authored
Add "map squared" pipe operators (#586)
1 parent 30d990e commit ac120e9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/FSharpPlus/Operators.fs

+13
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,19 @@ module Operators =
143143
/// <category index="1">Functor</category>
144144
let inline (|>>) (x: '``Functor<'T>``) (f: 'T->'U) : '``Functor<'U>`` = Map.Invoke f x
145145

146+
/// <summary>
147+
/// Lifts a function into two Functors.
148+
/// To be used in pipe-forward style expressions
149+
/// </summary>
150+
/// <category index="1">Functor</category>
151+
let inline (|>>>) (x: '``Functor1<Functor2<'T>>``) (f: 'T -> 'U) : '``Functor1<Functor2<'U>>`` = (Map.Invoke >> Map.Invoke) f x
152+
153+
/// <summary>
154+
/// Lifts a function into two Functors.
155+
/// </summary>
156+
/// <category index="1">Functor</category>
157+
let inline (<<<|) (f: 'T -> 'U) (x: '``Functor1<Functor2<'T>>``) : '``Functor1<Functor2<'U>`` = (Map.Invoke >> Map.Invoke) f x
158+
146159
/// <summary>
147160
/// Like map but ignoring the results.
148161
/// </summary>

tests/FSharpPlus.Tests/General.fs

+7
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,13 @@ module Functor =
396396
Assert.IsInstanceOf<Option<Async<int>>> (Some testVal10)
397397
areEqual 2 (testVal10 |> Async.RunSynchronously)
398398

399+
[<Test>]
400+
let mapSquared () =
401+
let x =
402+
[Some 1; Some 2]
403+
|>>> string
404+
Assert.AreEqual ([Some "1"; Some "2"], x)
405+
399406
[<Test>]
400407
let unzip () =
401408
let testVal = unzip {Head = (1, 'a'); Tail = [(2, 'b');(3, 'b')]}

0 commit comments

Comments
 (0)