在纯函数式编程中,执行顺序无关紧要,因此未确定(即由编译器决定).如果你有副作用,执行的顺序很重要.那么如何在F#中定义?
我有一个函数,递归删除给定路径的所有空子文件夹.此外,如果它们的名称在给定列表中,它将删除其中包含的一些文件.
算法很简单:
此外,该函数返回已删除元素的数量作为元组(已删除文件夹的数量,已删除文件的数量).
这是我的代码:
let rec DeleteEmptyFolders path filenames =
// Deletes a file or folder using the given function.
// Returns 1 if the file could be deleted, otherwise 0.
let Delete delete name =
try
delete name;
1
with
| _ -> 0
// The function result (number of deleted folders and files).
let deletedFolders (a, _) = a
let deletedFiles (_, a) = a
let accumulator a b =
( deletedFolders a + …Run Code Online (Sandbox Code Playgroud) 目前我有包含两个字符串的对象:
class myClass
{
public string string1 { get; set; }
public string string2 { get; set; }
public bool MatcheString1(string newString)
{
if (this.string1 == newString)
{
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我有一个第二个类,使用List列出上述对象.
class URLs : IEnumerator, IEnumerable
{
private List<myClass> myCustomList;
private int position = -1;
// Constructor
public URLs()
{
myCustomList = new List<myClass>();
}
}
Run Code Online (Sandbox Code Playgroud)
在那个类中,我正在使用一种方法来检查列表中是否存在字符串
// We can also check if the URL string is present in the collection
public bool ContainsString1(string newString) …Run Code Online (Sandbox Code Playgroud)