Coder Social home page Coder Social logo

linq-to-xml's People

Contributors

thomasbarnekow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

isabella232

linq-to-xml's Issues

xOrDefault

I love how your API is turning out.

I am still a bit concerned about making assumptions in your LinqIterableBase about what the defaults should be. In respect to selecting 'nodes', null is obviously a valid default, but you (or I) might be better served providing an .xOrNull() method to be more explicit.

// TypeScript
textNodes.select(parseFloat).firstOrDefault() // if textNodes is empty, the value returned here is null.
// C#
textNodes.Select(double.Parse).FirstOrDefault() // if textNodes is empty, the value returned here is 0.

As I pointed out before, when calling an .xOrDefault(), if for some reason T is of type number you won't get 0 as the default as you would in C#. And if you were attempting to filter by type: typeof null == 'object' where typeof undefined == 'undefined'. So the behavior differs even though you are conforming to the .NET API.

Where I see having null as an acceptable default is whenever the expected type should be an object like a node. It's just difficult to forsee how things might get weird if some amount of transformation is done by the consumer.

I'd also point to the weirdness in JS around 0 and null. Really strange things can happen that simply won't happen in C#.
https://www.tutorialspoint.com/what-is-the-relation-between-null-and-0-in-javascript
https://blog.campvanilla.com/javascript-the-curious-case-of-null-0-7b131644e274?gi=bc5bbbc977f4

null > 0 || null == 0; // == false
undefined > 0 || undefined == 0; // == false
undefined >= 0 // == false
null >= 0; // == true WHAT!?

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.