Jul. 26th, 2009

juan_gandhi: (Default)
  /**
   * Builds a degree object (x^n) for a given object.
   *
   * @param x the source object
   * @param n degree to which to raise object x
   * @return x^n and its projections to x
   * @TODO(vpatryshev): write good unitests
   */
  def degree(x: O, n: Int): Option[(O, List[A])] = {
    require(n >= 0, "Degree should be positive, we have " + n)
    if (n == 0) {
      terminal map(x => (x, List[A]()))
    }
    else {
      degree(x, n - 1) flatMap (
        value => {
          val (x_n_1, previous_projections) = value
          product(x, x_n_1) flatMap(
            xn => {
              val (p1, p_n_1) = xn
              val projections = p1 :: previous_projections map (m(p_n_1, _)) 
              Some((d0(p1), projections))
            }
          )
        }
      )
    }
  }


Seems like I am still learning to write code.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 2345 6
78 9 10 111213
14 151617 181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 22nd, 2025 07:57 am
Powered by Dreamwidth Studios