method-chaining

js method chain tail

北城余情 提交于 2019-12-11 18:41:51
问题 is there a way to detect if a method call in a chain (fluent interface) is in TAIL position in that chain ? var some = g.f(arg1).f(arg2).f(arg3); or do we absolutely need something like var some = g.f(arg1).f(arg2).f(arg3).end(); which I want avoid ? REturned value is not so important for me, but I need to compute something (an internal string-like key) at the end of the chain, with could have different lengths from one call to another. 回答1: No, there is no way to detect if a given method is

Output a property with PHP5 and method chaining

半城伤御伤魂 提交于 2019-12-11 14:06:11
问题 I am playing with PHP5 and method chaining, following several StackOverflow examples. I would like to set up a generic show() method able to print only the desired property, please see the example: <?php class testarea{ public function set_a(){ $this->property_a = 'this is a'.PHP_EOL; return $this; } public function set_b(){ $this->property_b = 'this is b'.PHP_EOL; return $this; } public function show(){ echo var_dump($this->property_a); // ->... generalize this return $this; } } $ta=new

Chaining REST calls in a pipeline while managing errors

ぐ巨炮叔叔 提交于 2019-12-11 09:43:54
问题 Coming from nodejs where I could chain asynchronous events using Promises and then operator I'm trying to explore how things are done in idiomatic F#. The calls I'm trying to chain are HTTP rest calls on some entity from creation to update to uploading images to publishing. Function composition says the output of one function should match the input of the second one to be composed and that common input and output in my case will be string , i.e. JSON serialized string as input and output of

Move from temporary used in method chaining

孤街浪徒 提交于 2019-12-11 08:37:14
问题 I am trying to do something similar to this: #include <vector> #include <memory> struct Bar { Bar& doThings() {return *this;} std::unique_ptr<int> m_content; // A non-copyable type }; struct Foo { Foo& append(Bar&& obj) { objects.push_back(std::move(obj)); return *this; } std::vector<Bar> objects; }; int test() { Foo test; test.append(std::move(Bar{}.doThings())) //Ok // Not ok .append(Bar{}.doThings()) ; } error: cannot bind rvalue reference of type Bar&& to lvalue of type Bar Is it possible

Why does Range.Address() return the address of the first cell when chained?

我与影子孤独终老i 提交于 2019-12-11 07:49:24
问题 I stumbled across some unexpected behavior when writing an answer for this question. When chaining together Range calls, Address always returns the address of the very first Range object in the statement. For example: Public Sub Unexpected() Debug.Print Range("B3").Address Debug.Print Range("B3").Range("A1").Address End Sub Returns the following output. $B$3 $B$3 But I would have expected it to return the Address of the last Range object in the chain. $B$3 $A$1 Can anyone explain this

overloading Ruby's […] Array creation shorthand

混江龙づ霸主 提交于 2019-12-10 17:25:14
问题 I've written a library that extends several base Ruby classes with observing wrappers mostly through method aliasing. However, I've hit a roadblock with the Array instantiation shorthand (e.g. @a = [1, 2, 3] ) I can't seem to find any method that's actually called in the creation of an Array object by the shorthand means. It's not an inherited #[] method in the current scope or inherited from any class or module in the ancestors chain. I've also overloaded or watched every method from the

Ruby Method Chaining

浪子不回头ぞ 提交于 2019-12-10 17:23:00
问题 I would like to chain my own methods in Ruby. Instead of writing ruby methods and using them like this: def percentage_to_i(percentage) percentage.chomp('%') percentage.to_i end percentage = "75%" percentage_to_i(percentage) => 75 I would like to use it like this: percentage = "75%" percentage.percentage_to_i => 75 How can I achieve this? 回答1: You have to add the method to the String class: class String def percentage_to_i self.chomp('%') self.to_i end end With this you can get your desired

PHP Method Chains - Reflecting?

戏子无情 提交于 2019-12-10 15:39:37
问题 Is it possible to reflect upon a chain of method calls to determine at what point you are in the chain of calls? At the very least, is it possible to discern whether a method is the last call in the chain? $instance->method1()->method2()->method3()->method4() Is it possible to do the same using properties that return instances of objects? $instances->property1->property2->property3->property4 回答1: If all the methods you're calling are returning the same object to create the fluent interface

JavaScript Chainable Method Delimma

泪湿孤枕 提交于 2019-12-10 14:11:42
问题 I have 2 methods that I'd like to use as chainable methods. Other methods may be chained to further modify text. left returns X characters from the left. right returns X characters from the right. Currently I can do this: var txt = "hello"; S$(txt).left(4).right(2).val //returns "ll" What I want to do is this. Basically I want to return the results after the last chained method without having to call the property. Is this possible? var txt = "hello"; S$(txt).left(4).right(2) //returns "ll"

Sequence Points and Method Chaining

喜欢而已 提交于 2019-12-10 12:34:23
问题 The following expression is often used to demonstrate undefined unspecified behaviour: f() + g() If f() and g() both have side effects on some shared object then the behaviour is undefined unspecified because the order of execution is unknown. f() may be evaluated before g() or vice versa. Now I was wondering what happens when you chain member functions on an object. Let's say I have an instance of a class, the instance called obj and it has two member functions, foo() and bar() which both