Questions tagged [chain]

Use the tag "method-chaining' if referring to the invocation of multiple methods against a single object. Chaining is the general idea of linking many smaller processes together to form a large process.

Method Chaining allows you to run multiple methods against an object on one line of code.

For example in Java the methods setName and setAge are chained:

Person person = new Person();        //instantiate a new person object.
person.setName("Peter").setAge(21);  //set the name, and age of object person.

First the method setName is applied to the object, then setAge.

Each method returns an object, allowing any number of calls to be chained together in a single statement.

561 questions
3129
votes
21 answers

How do I make function decorators and chain them together?

How do I make two decorators in Python that would do the following? @make_bold @make_italic def say(): return "Hello" Calling say() should return: "Hello"
Imran
  • 87,203
  • 23
  • 98
  • 131
38
votes
3 answers

How to properly break out of a promise chain?

Based on the question here: jQuery chaining and cascading then's and when's and the accepted answer, I want to break the promise chain at a point but haven't yet found the correct way. There are multiple posts about this, but I am still lost. Taking…
Dennis G
  • 21,405
  • 19
  • 96
  • 133
28
votes
3 answers

What is the use of filter and chain in servlet?

chain.doFilter(req,res); We used this in a servlet program. I want to know what is the use of the method doFilter() in a servlet? Also what is the use of filter and chain concept in Java servlets?
Vinoth Kumar
  • 3,243
  • 7
  • 24
  • 13
25
votes
3 answers

$q promise error callback chains

In the following code snippet error 1 and success 2 will be logged. How can I can I propagate error callbacks being invoked rather than the success callbacks being invoked if the original deferred is rejected. angular.module("Foo",…
Steven Wexler
  • 16,589
  • 8
  • 53
  • 80
24
votes
3 answers

How to make chainable function in JavaScript?

Lets imagine function like this: function foo(x) { x += '+'; return x; } Usage of it would be like: var x, y; x = 'Notepad'; y = foo(x); console.log(y); // Prints 'Notepad+'. I'm looking for a way to create function that's chainable with…
daGrevis
  • 21,014
  • 37
  • 100
  • 139
20
votes
1 answer

Chaining Singles together in RxJava

I am using RxJava in my android app along with Retrofit to make network requests to a server. I am using RxJavaCallAdapterFactory so I can have my retrofit requests return singles. In my code, the retrofit object is named 'api'. The code here works…
Jtvd78
  • 4,135
  • 5
  • 20
  • 21
20
votes
3 answers

How to route a chain of tasks to a specific queue in celery?

When I route a task to a particular queue it works: task.apply_async(queue='beetroot') But if I create a chain: chain = task | task And then I write chain.apply_async(queue='beetroot') It seems to ignore the queue keyword and assigns to the…
mpaf
  • 6,597
  • 6
  • 38
  • 42
19
votes
2 answers

Promise: Ignore Catch and Return to Chain

Is it possible to ignore a catch and return back to the chain? promiseA() // <-- fails with 'missing' reason .then(promiseB) // <-- these are not going to run .then(promiseC) .catch(function(error, ignore){ if(error.type ==…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
18
votes
5 answers

Piping (or command chaining) with QProcess

I'm using Qt and bash over it, need to execute something like: bash: cat file | grep string in Qt: QString cmd = "cat file | grep string"; QProcess *process = new…
Konstantin Ivanov
  • 245
  • 1
  • 3
  • 6
17
votes
2 answers

Promises: Execute something regardless of resolve/reject?

Using the Promises design pattern, is it possible to implement the following: var a, promise if promise.resolve a = promise.responsevalue; if promise.reject a = "failed" AFTER resolution/rejection. Not ASYNC!! send a somewhere,…
nikjohn
  • 20,026
  • 14
  • 50
  • 86
15
votes
2 answers

How to share tasks between vscode workspace folders?

My VSCode project is multi-root workspace. That is I have multiple workspaces each in separate directories, each has a .vscode folder. I'm trying to build a workspace with dependencies between each module via build tasks. I've tried to set dependsOn…
alex
  • 425
  • 4
  • 21
15
votes
5 answers

get lhs object name when piping with dplyr

I'd like to have a function that can use pipe operator as exported from dplyr. I am not using magrittr. df %>% my_function How can I get df name? If I try my_function <- function(tbl){print(deparse(substitute(tbl)))} it returns [1] "." while I'd…
15
votes
12 answers

How better refactor chain of methods that can return null in java?

I have code like: obj1 = SomeObject.method1(); if (obj1 != null) { obj2 = obj1.method2(); if (obj2 != null) { obj3 = obj2.method3(); if (obj3 != null) { ............ return objN.methodM(); } } } .... I have…
user710818
  • 23,228
  • 58
  • 149
  • 207
13
votes
3 answers

Celery Task Chain and Accessing **kwargs

I have a situation similar to the one outlined here, except that instead of chaining tasks with multiple arguments, I want to chain tasks that return a dictionary with multiple entries. This is -- very loosely and abstractly --- what I'm trying to…
Benjamin White
  • 779
  • 6
  • 25
12
votes
2 answers

attempting to break jQuery promise chain with .then, .fail and .reject

Update: this issue was a result of jQuery 1.7 vs 1.8. Do not ever use promises in 1.7 beacuse they aren't chainable with returning a promise inside a .then. 1.8 looks like they didn't mess it up. http://jsfiddle.net/delvarworld/28TDM/ // make a…
Andy Ray
  • 30,372
  • 14
  • 101
  • 138
1
2 3
37 38