lazy-evaluation

Haskell foldr results in type error while foldl doesn't

不羁岁月 提交于 2019-12-11 12:10:26
问题 I'm working through "Haskell Programming From First Principles". In the chapter on Folding Lists, exercise 5f, when I evaluate foldr const 'a' [1..5] I get No instance for (Num Char) arising from the literal ‘1’ However, with foldl const 'a' [1..5] I get 'a' . I get that the folds are lazy, foldr doesn't traverse the spine and foldl does. But even looking at the definitions of foldr and foldl, foldr f z [] = z foldr f z (x:xs) = f x (foldr f z xs) foldl f z [] = z foldl f z (x:xs) = foldl f

Creating an unevaluated function call with unevaluated arguments

血红的双手。 提交于 2019-12-11 11:40:48
问题 If we call a function directly in R, lazy evaluation takes place, so that the function arguments are not evaluated until they are encountered in the function body. An effect of this is that using match.call() at the beginning of a function, say a model fitter like lm , captures the call with unevaluated function arguments. Thus, the call to the function can be retrieved with promises instead of evaluated arguments by executing the model fitting function. The disadvantage of this is that the

doAnswer in mockito - when is it lazy evaluation and when is it eager?

独自空忆成欢 提交于 2019-12-11 10:49:41
问题 I'm using mockito spy with this code: Mockito.doAnswer(new Answer() { Object answer(InvocationOnMock invocation) { ImagesSorter mock = (ImagesSorter) invocation.getMock(); Object[] args = invocation.getArguments(); return mock.sortImages((List<Image>) args[0], (UserInfo) args[1], fakeNowDate); } }).when(imagesSorterSpy).sortImages(imagesAsInsertionOrder, user); And I see the answer() is called eagerly when the struct is: when(spy.method())./*...*/. but it's lazy evaluation when the struct is:

Thread - safe singelton

人盡茶涼 提交于 2019-12-11 09:38:02
问题 I have a class which has 3 static members. Each of static member is not thread-safe singleton. I need to provide a thread safe implementation for their use.Is it ok?Or I need to provide thread-safe wrapper for each of them? If I should - how can I do it using Lazy<T> ? Additional question : Measure() and Do() of SingeltonClass1/2/3 are not thread-safe is func1() thread-safe? public class MyLazySingleton { // static holder for instance, need to use lambda to construct since constructor private

MEF Lazy ImportMany with Creationpolicy.NonShared

有些话、适合烂在心里 提交于 2019-12-11 08:14:43
问题 i'm a beginner in mef and so i have a question :) i have the following: [PartCreationPolicy(CreationPolicy.Shared)] [Export(typeof(SharedExport))] public class SharedExport : INPCBase { [ImportMany(typeof(INonShared),RequiredCreationPolicy = CreationPolicy.NonShared)] private IEnumerable<Lazy<INonShared,Dictionary<string,object>>> fac; ... public void Open() { foreach (var lazy in fac) { this.Muster.Add(lazy.Value); } } the imported classes all marked as nonshared. [PartCreationPolicy

Custom ListView?

故事扮演 提交于 2019-12-11 07:19:28
问题 I have a code made by Fedor, it can be found "here". The first image is what I have now, and the second image is what I want to accomplish. Can someone guide me with this. I have been struggling for days trying to solve this problem. Please help me, Thanks in advance! 回答1: You just need to modify the list item layout (in item.xml) to have another ImageView. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap

How to change the CSS after image lazy loading (jQuery)? [closed]

蹲街弑〆低调 提交于 2019-12-11 06:58:44
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I've got the following problem: after the user clicks on a thumbnail image, a bigger image is loaded with lazy loading and opens up. The code to load the bigger image is: <img width="663" height="845" class="big"

Understanding R function lazy evaluation

情到浓时终转凉″ 提交于 2019-12-11 06:12:28
问题 I'm having a little trouble understanding why, in R, the two functions below, functionGen1 and functionGen2 behave differently. Both functions attempt to return another function which simply prints the number passed as an argument to the function generator. In the first instance the generated functions fail as a is no longer present in the global environment, but I don't understand why it needs to be. I would've thought it was passed as an argument, and is replaced with aNumber in the

Lazy Evaluation in SparkSQL

只愿长相守 提交于 2019-12-11 04:20:53
问题 In this piece of code from the Spark Programming Guide, # The result of loading a parquet file is also a DataFrame. parquetFile = sqlContext.read.parquet("people.parquet") # Parquet files can also be registered as tables and then used in SQL statements. parquetFile.registerTempTable("parquetFile"); teenagers = sqlContext.sql("SELECT name FROM parquetFile WHERE age >= 13 AND age <= 19") teenagers.collect() What exactly happens in the Java heap (how is the Spark memory managed) when each line

Clojure core.async. How to download lazily with go block inside with-open?

99封情书 提交于 2019-12-11 03:48:02
问题 It`s a continuation of my previous question How to produce a lazy sequence by portion in clojure? I want download data from a database by portions. Initially I download first 500 rows and then I send a request to fetch next 500 rows and so on until I receive all data from a server. I wrote the code: (jdbc/atomic conn (with-open [cursor (jdbc/fetch-lazy conn [sql_query])] (let [lazyseq (jdbc/cursor->lazyseq cursor) counter (atom 1)] (swap! lazyseq_maps assoc :session_id {:get_next? (chan 1)