Skip to content

Commit

Permalink
+ Tuple2 and Tuple3 extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
gusty authored and wallymathieu committed Jun 15, 2020
1 parent 256ea1a commit dc0b586
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/FSharpPlus/Data/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module State =
let map f (State m) = State (fun s -> let (a: 'T, s') = m s in (f a, s')) : State<'S,'U>

/// Combines two States into one by applying a mapping function.
let map2 (f: 'T->'U->_) (State x) (State y) = State (fun s -> let (g, s1) = mapItem1 f (x s) in mapItem1 g (y s1)) : State<'S,'V>
let map2 (f: 'T->'U->_) (State x) (State y) = State (fun s -> let (g, s1) = Tuple2.mapItem1 f (x s) in Tuple2.mapItem1 g (y s1)) : State<'S,'V>

let bind f (State m) = State (fun s -> let (a: 'T, s') = m s in run (f a) s') : State<'S,'U>
let apply (State f) (State x) = State (fun s -> let (f', s1) = f s in let (x': 'T, s2) = x s1 in (f' x', s2)) : State<'S,'U>
Expand Down
14 changes: 14 additions & 0 deletions src/FSharpPlus/Extensions/Tuple.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace FSharpPlus

/// Additional operations on Tuple (,)
[<RequireQualifiedAccess>]
module Tuple2 =
let mapItem1 f (x, y) = (f x, y)
let mapItem2 f (x, y) = (x, f y)

/// Additional operations on Tuple (,,)
[<RequireQualifiedAccess>]
module Tuple3 =
let mapItem1 f (x, y, z) = (f x, y, z)
let mapItem2 f (x, y, z) = (x, f y, z)
let mapItem3 f (x, y, z) = (x, y, f z)
3 changes: 2 additions & 1 deletion src/FSharpPlus/FSharpPlus.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<!--<OutputPath>..\..\bin</OutputPath>-->
</PropertyGroup>
<ItemGroup>
<Compile Include="Internals.fs" />
<Compile Include="Internals.fs" />
<Compile Include="Extensions/Option.fs" />
<Compile Include="Extensions/Nullable.fs" />
<Compile Include="Extensions/Result.fs" />
Expand All @@ -51,6 +51,7 @@
<Compile Include="Extensions/Task.fs" />
<Compile Include="Extensions/Async.fs" />
<Compile Include="Extensions/Extensions.fs" />
<Compile Include="Extensions/Tuple.fs" />
<Compile Include="TypeLevel/TypeLevelOperators.fs" />
<Compile Include="TypeLevel/TypeBool.fs" />
<Compile Include="TypeLevel/TypeNat.fs" />
Expand Down

0 comments on commit dc0b586

Please sign in to comment.