List Extensions > A clever way to filter lists.

About Monkey 2 Forums Monkey 2 Projects List Extensions > A clever way to filter lists.

This topic contains 3 replies, has 3 voices, and was last updated by  cocon 2 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6736

    cocon
    Participant

    After I was tired of implementing loops in my code, I started to experiment with some functional programming concepts. In this case, I am interested to filter some lists.

     

     

    And for people who prefer lambdas instead of interfaces.

     

    Perhaps you might ask why use interface instead of lambda functions? Because interfaces have strong concept behind them, they enforce an architecture upon the code. Otherwise lambdas are much better for plain and straight away usage.

    The interface implementation it is used in some different scenarios as well. I remember once I used this concept in Java to sort some custom made classes. So virtually the concept is that when you want to “inject” your custom logic dynamically into another method you go with this approach.

    #6742

    nerobot
    Participant

    Nice example. And for docs/samples collection too.

    Also there can be a version with ‘outList’ extra  parameter to allow users reuse one list for output values. And such variant can return added elements count. 🙂

    #6834

    degac
    Participant

    I agree.
    TO put immediately on wiki/documentation.

    Thanks a lot!

    #7480

    cocon
    Participant

    After of revisiting this idea, I noticed that this actually leads to functional programming concept such as LINQ etc. From what I guess Monkey 2 will feature LINQ in the future, so I won’t plan to do a re-implementation of that. However only as an evolution of the first example, this is more of a prototype for exploring the concept further. This time I took it a step further to use Extension methods to the List class rather than writing “service classes”, this way the API becomes fluent and natural. Perhaps in the future if I get any further ideas with this it will justify the creation of a library.

    The most possible future plan in mind, is to port some little game examples (perhaps some bananas) to this style of programming and see in real terms what are the benefits. 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.