Skip to content

Commit

Permalink
Add file move to FileIO
Browse files Browse the repository at this point in the history
  • Loading branch information
TomOpenSource committed Oct 1, 2023
1 parent bce0a16 commit 771d68d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LanguageExt.Sys/Live/FileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public Unit Copy(string fromPath, string toPath, bool overwrite = false)
return default;
}

/// <inheritdoc/>
public Unit Move(string fromPath, string toPath)
{
File.Move(fromPath, toPath);
return default;
}

#if NET5PLUS
/// <summary>
/// Append lines to the end of a file
Expand Down
11 changes: 11 additions & 0 deletions LanguageExt.Sys/Sys/IO/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public static class File<RT>
public static Eff<RT, Unit> copy(string fromPath, string toPath, bool overwrite = false) =>
default(RT).FileEff.Map(e => e.Copy(fromPath, toPath, overwrite));

/// <summary>
/// Move file
/// </summary>
/// <param name="fromPath">Source path</param>
/// <param name="toPath">Destination path</param>
/// <typeparam name="RT">Runtime</typeparam>
/// <returns>Unit</returns>
[Pure, MethodImpl(AffOpt.mops)]
public static Eff<RT, Unit> move(string fromPath, string toPath) =>
default(RT).FileEff.Map(e => e.Move(fromPath, toPath));

/// <summary>
/// Append lines to the end of the file provided
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions LanguageExt.Sys/Test/FileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public FileIO(MemoryFS fs, DateTime now) =>
public Unit Copy(string fromPath, string toPath, bool overwrite = false) =>
fs.CopyFile(fromPath, toPath, overwrite, now);

/// <inheritdoc/>
public Unit Move(string fromPath, string toPath) =>
fs.Move(fromPath, toPath, now);

/// <summary>
/// Append lines to the end of a file
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions LanguageExt.Sys/Traits/FileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public interface FileIO
/// </summary>
Unit Copy(string fromPath, string toPath, bool overwrite = false);

/// <summary>
/// Move file from one place to another
/// </summary>
/// <exception cref="IOException">The <paramref name="toPath"/> exists or <paramref name="fromPath"/> was not found.</exception>
Unit Move(string fromPath, string toPath);

/// <summary>
/// Append lines to the end of a file
/// </summary>
Expand Down

0 comments on commit 771d68d

Please sign in to comment.