higher-order-functions

How to use expand in snakemake when some particular combinations of wildcards are not desired?

為{幸葍}努か 提交于 2019-11-27 08:19:27
问题 Let's suppose that I have the following files, on which I want to apply some processing automatically using snakemake: test_input_C_1.txt test_input_B_2.txt test_input_A_2.txt test_input_A_1.txt The following snakefile uses expand to determine all the potential final results file: rule all: input: expand("test_output_{text}_{num}.txt", text=["A", "B", "C"], num=[1, 2]) rule make_output: input: "test_input_{text}_{num}.txt" output: "test_output_{text}_{num}.txt" shell: """ md5sum {input} >

Higher order function: “Cannot invoke 'map' with an argument list of type '((_) -> _)'”

拥有回忆 提交于 2019-11-27 07:02:51
问题 I would like to use a swift higher order function (map) to remove all Subviews from a given UIView.subviews array. The line (cell.contentView.subviews as [UIView]).map { $0.removeFromSuperView() } causes the error "Cannot invoke 'map' with an argument list of type '((_) -> _)'" I would like to know what the compiler needs from me at this point. 回答1: I would say that map is not for this kind of operation. It creates a new sequence based on an others sequences elements, but what you don't want

Does PHP have an equivalent to Python's list comprehension syntax?

早过忘川 提交于 2019-11-27 05:34:32
问题 Python has syntactically sweet list comprehensions: S = [x**2 for x in range(10)] print S; [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] In PHP I would need to do some looping: $output = array(); $Nums = range(0,9); foreach ($Nums as $num) { $out[] = $num*=$num; } print_r($out); to get: Array ( [0] => 0 [1] => 1 [2] => 4 [3] => 9 [4] => 16 [5] => 25 [6] => 36 [7] => 49 [8] => 64 [9] => 81 ) Is there anyway to get a similar list comprehension syntax in PHP? Is there anyway to do it with any of the new

Higher-order functions in Javascript

社会主义新天地 提交于 2019-11-27 01:03:48
I am reading Eloquent JavaScript ( The new edition ) and I reached the part on higher order functions and I'm confused on what's happening in the following code. function noisy(f) { return function(arg) { console.log("calling with", arg); var val = f(arg); console.log("called with", arg, "- got", val); return val; }; } noisy(Boolean)(0); // → calling with 0 // → called with 0 - got false Why is the call to the function noisy like this? Is (Boolean) a cast? A cast for what? the return value? or the argument? why not (Boolean)noisy(0) if its the return value. Or noisy((Boolean) 0) if the

higher level functions in R - is there an official compose operator or curry function?

亡梦爱人 提交于 2019-11-26 23:56:52
问题 I can create a compose operator in R: `%c%` = function(x,y)function(...)x(y(...)) To be used like this: > numericNull = is.null %c% numeric > numericNull(myVec) [2] TRUE FALSE but I would like to know if there is an official set of functions to do this kind of thing and other operations such as currying in R. Largely this is to reduce the number of brackets, function keywords etc in my code. My curry function: > curry=function(...){ z1=z0=substitute(...);z1[1]=call("list"); function(...){do

Lifting a higher order function in Haskell

試著忘記壹切 提交于 2019-11-26 22:40:58
I'm trying to construct a function of type: liftSumthing :: ((a -> m b) -> m b) -> (a -> t m b) -> t m b where t is a monad transformer. Specifically, I'm interested in doing this: liftSumthingIO :: MonadIO m => ((a -> IO b) -> IO b) -> (a -> m b) -> m b I fiddled with some Haskell wizardry libs and but to no avail. How do I get it right, or maybe there is a ready solution somewhere which I did not find? This can't be done generically over all MonadIO instances because of the IO type in a negative position. There are some libraries on hackage that do this for specific instances ( monad-control

How to use ES6 Fat Arrow to .filter() an array of objects

瘦欲@ 提交于 2019-11-26 22:29:33
问题 I'm trying to use ES6 arrow function with .filter to return adults (Jack & Jill). It appears I cannot use an if statement. What do I need to know in order to do this in ES6? var family = [{"name":"Jack", "age": 26}, {"name":"Jill", "age": 22}, {"name":"James", "age": 5 }, {"name":"Jenny", "age": 2 }]; let adults = family.filter(person => if (person.age > 18) person); // throws error (8:37) SyntaxError: unknown: Unexpected token (8:37) |let adults = family.filter(person => if (person.age > 18)

Higher order functions in C

佐手、 提交于 2019-11-26 20:54:18
问题 Is there a "proper" way to implement higher order functions in C. I'm mostly curious about things like portability and syntax correctness here and if there are more than one ways what the merits and flaws are. Edit: The reason I want to know how to create higher order functions are that I have written a system to convert PyObject lists (which you get when calling python scripts) into a list of C structures containing the same data but organized in a way not dependant on the python.h libraries

zipWith (mapping over multiple Seq) in Scala

 ̄綄美尐妖づ 提交于 2019-11-26 19:49:38
问题 Suppose I have val foo : Seq[Double] = ... val bar : Seq[Double] = ... and I wish to produce a seq where the baz(i) = foo(i) + bar(i). One way I can think of to do this is val baz : Seq[Double] = (foo.toList zip bar.toList) map ((f: Double, b : Double) => f+b) However, this feels both ugly and inefficient -- I have to convert both seqs to lists (which explodes with lazy lists), create this temporary list of tuples, only to map over it and let it be GCed. Maybe streams solve the lazy problem,

Higher-order functions in Javascript

时间秒杀一切 提交于 2019-11-26 09:33:50
问题 I am reading Eloquent JavaScript (The new edition) and I reached the part on higher order functions and I\'m confused on what\'s happening in the following code. function noisy(f) { return function(arg) { console.log(\"calling with\", arg); var val = f(arg); console.log(\"called with\", arg, \"- got\", val); return val; }; } noisy(Boolean)(0); // → calling with 0 // → called with 0 - got false Why is the call to the function noisy like this? Is (Boolean) a cast? A cast for what? the return