Geeks With Blogs
AngelEyes on .Net Tips, tricks and WTFs about Asp .Net, SQL Server and the likes.

This is long overdo... Just a short and simple example of Partial Function Application.

 

For some good explanations, which also include the difference between Currying and Partial Function Application, check out:

http://msmvps.com/blogs/jon_skeet/archive/2012/01/30/currying-vs-partial-function-application.aspx

and also this answer on stackoverflow: http://stackoverflow.com/a/8826698/532517

 

And here is the example, taken from real code:

 

        internal void Addfile(string parentDirName, string fileName, long size)

        {

            AddElement(parentDirName, fileName, (name, parent) => new File(name, size, parent));

        }

 

        public void AddDir(string parentDirName, string dirName)

        {

            AddElement(parentDirName, dirName, (name, parent) => new Directory(dirName, parent));

        }

 

        private void AddElement(string parentDirName, string name,

                                Func<stringFileSystemElementFileSystemElement> elementCreator)

        {

            ValidateFileNames(parentDirName, name);

            var parent = (Directory)_index[parentDirName];

            FileSystemElement element = elementCreator(name, parent);

            parent._elements.Add(element);

            _index.Add(name, element);

        }

Posted on Thursday, September 27, 2012 11:20 AM | Back to top


Comments on this post: Partial Function Application

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © AngelEyes | Powered by: GeeksWithBlogs.net