This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var elements = document.querySelectorAll("div"), | |
| callback = (el) => { console.log(el); }; | |
| // Spread operator | |
| [...elements].forEach(callback); | |
| // Array.from() | |
| Array.from(elements).forEach(callback); | |
| // for...of statement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ArgumentError: missing keyword: input_b, when using: Defaults::Result1, to calculate: result_1 | |
| from /Users/rusilko/Projects/creditor/evaluate.rb:78:in `block in call' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ArgumentError: missing keyword: input_b | |
| from /Users/rusilko/Projects/creditor/evaluate.rb:78:in `block in call' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def evaluation_steps | |
| { | |
| result_1: ::Defaults::Result1, | |
| result_2: ::Defaults::Result2, | |
| result_3: lambda { |input_a:, input_b:, **kwargs| input_a + input_b } | |
| } | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OUTPUT = { | |
| input_a: 10, | |
| input_b: 20, | |
| input_c: 30, | |
| result_1: 60, | |
| result_2: 18.2 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Evaluate | |
| def call(input_data, bank) | |
| initial_data = input_data.merge(bank.parameters) | |
| steps = bank.evaluation_steps | |
| steps.inject(initial_data) do |data, (result_name, calculate_result)| | |
| begin | |
| data.merge({ result_name.to_sym => calculate_result.(data) }) | |
| rescue ArgumentError | |
| raise $!, "#{$!}, when using: #{calculate_result}, to calculate: #{result_name}", $!.backtrace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BankA | |
| module Result3 | |
| def self.call(result_1:, result_2:, **kwargs) | |
| result_1 - result_2 | |
| end | |
| end | |
| def evaluation_steps | |
| { | |
| result_1: ::Defaults::Result1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Evaluate | |
| def call(input_data, bank) | |
| initial_data = input_data.merge(bank.parameters) | |
| steps = bank.evaluation_steps | |
| steps.inject(initial_data) do |data, (result_name, calculate_result)| | |
| data.merge({ result_name.to_sym => calculate_result.(data) }) | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DataWrapper | |
| def initialize(data_hash) | |
| raise ArgumentError unless data_hash.is_a? Hash | |
| @data_hash = data_hash | |
| end | |
| def add(name, value) | |
| DataWrapper.new(data_hash.merge({ name.to_sym => value })) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RAW_INPUT = { | |
| input_a: 10, | |
| input_b: 20, | |
| input_c: 30 | |
| } |
NewerOlder