Giter VIP home page Giter VIP logo

functional's People

Contributors

chriskuech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

functional's Issues

Merge-Object piping non-existent variable to Reduce-Object

The Merge-Object function pipes $input to Reduce-Object, but the $input variable is not created anywhere. It looks like it should be piping the $Object parameter of the Merge-Object function.

Consequently, when I ran the Merge-Object function, I was getting no output, because it is always sending $null to Reduce-Object.

Powershell: functional: reduce: How to initialize the reduce accumulator?

I want to use the functional "reduce" function to calculate things, such as the factorial of a number. e.g. The factorial of 5 is 5x4x3x2x1 = 120. In Ruby I can do it with something like:

# factorial1.rb

(1..5).reduce{|accumulator,element| accumulator*element}

In Powershell I would do something like:

# factorial.ps
# ------ Install this library before using the "reduce" function
# Install-Module -Name functional

1..5 | reduce {$a*$b}  

In both languages, the answer is 120, and the accumulator is assumed to be an integer, with an
initial value of the first element in the range.

If I redefined the factorial to have an initial value of 10, in Ruby I
would code it as

# factorial2.rb
# (1..5).reduce    {|accumulator,element| accumulator*element} #uninitialized accumulator
  (1..5).reduce(10){|accumulator,element| accumulator*element}

This yields the expected answer of 1200.

QUESTION 1: How does one initialize a "reduce" accumulator in Powershell?

In the next scenario, I want to generate a list of factorials. If
I were to code it in Ruby, I could initialize the reduce accumulator
with [1] (because 0! is 1), resulting in the following code:

# factorial.rb
# (1..5).reduce     {|accumulator,element| accumulator*element}  #uninitialized accumulator
  (1..5).reduce([1]){|accumulator,element| accumulator << accumulator[-1]*element}

The output looks something like

   => [1, 1, 2, 6, 24, 120]

QUESTION 2: How does one use an expandible array to initialize the accumulator for the
Powershell "reduce" function of the "functional" module?

bottom example in the readme doesn't work

Merge-Object @{a = @{b = 1}} @{a = @{c = 2}} -Strategy Fail
Merge-Object : A positional parameter cannot be found that accepts argument 'System.Collections.Hashtable'.
At line:1 char:1
+ Merge-Object @{a = @{b = 1}} @{a = @{c = 2}} -Strategy Fail
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Merge-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Merge-Object

I found reading the pester tests helpful.

How would you do compare-object?

Reduce-Object with custom value

It would be really helpful to generalize the "Reduce-Object", adding also an initial value inline to be used as accumulator.
I'm not quite sure on how would it be the idiomatic way to go with Powershell.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.