GithubHelp home page GithubHelp logo

Comments (7)

atifaziz avatar atifaziz commented on May 24, 2024

About to delete my previous comment, which was unnecessarily wordy...

A few notes...

  1. There is a concept from functional programming called an "unfold", which is the projection of a single entity into a collection via a repeated or recursive operation. Our Generate method in its current form is a special case of the "unfold" operation. It supports value-based unfolding well, but when you start working with more complex objects, usability breaks down.

  2. An "unfold" on complex objects is much more of a graph transformation operation than a querying/filtering operation. So far, LINQ itself as well as MoreLinq have been focused on querying and filtering. It may be that the more general "unfold" is useful, but more appropriately bundled with similar functionality. FWIW, I would argue that querying/filtering is a special case of graph transformation, and a querying/filtering DSL (even up to and including SQL itself) could benefit greatly from access to more general graph transformation operations. But MoreLinq may not be the place to start providing this.

  3. The Generate name pairs up well with its inverse operation provided in the .NET Framework v3.5: Aggregate. Were we working in a functional environment rather than procedural, these would probably be called Unfold and Fold, respectively. But since we can't change Aggregate, I'm in favor of keeping the Generate name or something similarly untuitively connected to Aggregate.


Reported by @cammerman on 2009-03-10 23:49:42

from morelinq.

atifaziz avatar atifaziz commented on May 24, 2024

No problem. I only just noticed Jared Parson has put together a lot of his excellent work on
functional/immutable coding as a library called BclExtras on the MSDN code gallery. It has a lot of interesting stuff and looks a little closer to what I was looking for - it sounds like you have a specific plan for what MoreLinq will cover.


Reported by daniel.earwicker on 2009-03-21 09:54:42

from morelinq.

atifaziz avatar atifaziz commented on May 24, 2024

Reported by @atifaziz on 2009-04-04 19:28:51

  • Labels added: Type-Enhancement
  • Labels removed: Type-Defect

from morelinq.

leandromoh avatar leandromoh commented on May 24, 2024

As already mentioned by CAmmerman, unfold function can solve it;

Exception innermost = Unfold(caught, e => e.InnerException != null ? Tuple.Create(e, e.InnerException) : null).Last();

from morelinq.

leandromoh avatar leandromoh commented on May 24, 2024

@atifaziz will you close this issue now that unfold were implemented ?

from morelinq.

atifaziz avatar atifaziz commented on May 24, 2024

@leandromoh Yep & thanks for helping & remembering to triage this.

from morelinq.

atifaziz avatar atifaziz commented on May 24, 2024

In the final form Unfold was released in 2.3, the example of traversing nested exceptions to find the innermost will look like this:

var innermost = 
    MoreEnumerable.Unfold(caught, e => e, e => e != null, e => e.InnerException, e => e)
                  .Last();

from morelinq.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.