score:2
try this:
public static iobservable<list<string>> geturllist(uri url)
{
var result = (
from request in observable.return(
getwebrequest(url, false))
from response in observable.fromasyncpattern<webresponse>(
request.begingetresponse, request.endgetresponse)()
from item in geturlcollection(response)
.toobservable()
.toarray()
select item
.tolist());
return result;
}
my only concern with this whole approach is that your geturlcollection(response)
is returning an enumerable. you really should code this to return an observable.
score:1
hmmm i think observable.start is your friend here. you have a bunch of code that it looks like you are forcing into observable sequences, when they really don't look like they are.
remember rx is designed to work with sequences of push data. you seem to have a sequence of 1 that happens to be a list. tpl/task/async would be a good fit here.
if you do want to use rx, i would suggest avoiding boucing around between ienumable and iobservable. doing so is a quick way to creating nasty race conditions and confusing the next developer.
public static iobservable<list<string>> geturllist(uri url)
{
return observable.start(()=>
{
var request = getwebrequest(url, false);
return geturlcollection(request);//code change here??
});
}
here you can happily be synchronous in your observable.start delegate. this should be a lot easier for the next guy to understand (i.e. this is a single value sequence with the urlcollection as the value).
Source: stackoverflow.com
Related Query
- Cannot implicitly convert type system linq IQueryable to system collections generic List
- Convert System collection list <anonymous> to generic list<myviewmodel> ASP.NET-MVC5
- List or Array of String Contain specific word in Html Source Code
- How to write a query in order to achieve the orderby descending clause for an uninitialised generic collections such as List of integers in c#?
- c# Linq or code to extract groups from a single list of source data
- How can I sort generic list DESC and ASC?
- Subtract a generic list from another
- Convert DataTable to Generic List in C#
- Find an item in a generic list by specifying multiple conditions
- How to use .Where in generic list
- Simplest way to filter value from generic List in C# using LINQ
- Gridview using a generic list as DataSource and Auto-generating columns
- Converting a XML to Generic List
- Generic List to EntitySet Conversion
- Generic List .First not working LINQ
- Generating the Shortest Regex Dynamically from a source List of Strings
- Visual Studio Code Analysis Rule - "Do not expose generic lists"
- Auto-incrementing a generic list using LINQ in C#
- Remove a property/column from a generic list
- Generic List to CSV String
- C# Generic List Union Question
- Delete an element from a generic list
- Linq OrderBy on generic list returns not entirely alphabetical list
- Sorting a generic list by an external sort order
- How to convert Generic List<anonymous type > to Generic List <Classname>?
- Execute method for each object in generic list using lambda
- LINQ Source Code Available
- Checking for item in Generic List before using it
- Removing Duplicates from bottom of Generic List
- .NET 4 Code Contracts: "requires unproven: source != null"
More Query from same tag
- Can I use predefined namespaces when loading an XDocument?
- Check if parameter value is null or not inside query
- LINQ: Select Elements that Only Appear Once in a List
- Convert Object[] to specific type
- Linq - where a record contains any items within another collection
- How to call function inside linq anonymous function
- system.collections.generic.list to system.collections.generic.ienumerable
- Apply Where conditionally (OR between them) LINQ
- Linq observable collection cast error
- Projecting an entity to an anonymous object while some of its navigation properties might be null
- Entity Framework FirstOrDefault overrides with constructor values?
- Getting current item from select in Lambda expression?
- Two seemingly identical LINQ queries. One works, the other doesn't
- Why does this CollectionAssert.AreEquivalent() test fail?
- Does LINQ know how to optimize "queries"?
- Better way of comparing two lists with LINQ?
- Suppression State Error CS0266 When Selecting Data From Database Using LINQ
- Is ToArray() optimized for arrays?
- Inner join linq to webgrid
- dilemma on the use of inheritance in EF code-first
- Better version of Compare Extension for Linq
- How do I "select null as "Column" Using LINQ in C#
- LINQ - joining two tables and getting the values from the right part of the join if it exists throw exception
- How do I use linq to fill dictionary with default values?
- Like in Lambda Expression and LINQ
- Concat Two IQueryables with Anonymous Types?
- Determine the source DataContext for a Linq to Sql query
- converting a t-sql query to Linq to Sql with coalesce and multiple join
- Selecting elements from XML file using LINQ
- Complex/Nested XML Reading in C#