noodling around with algebra
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Trying to make some semigroups

I feel like I've gotten a step closer, but still not quite there.

import org.conbere.algebra.SemiGroup._

object Algebra {
  def main(args:Array[String]) = {
    // this works great
    val adder = optionSemiGroup[Int]
    assert(Some(3) == adder(Some(1), Some(2)))

    // this doesn't
    // scala> Some(1) +| Some(2)
    // <console>:11: error: could not find implicit value for parameter adder: org.conbere.algebra.SemiGroup[Some[Int]]
    //               Some(1) +| Some(2)
    Some(1) +| Some(2)

So here's some examples

import org.conbere.algebra.SemiGroup._
val adderInt = optionSemiGroup[Int]
val adderString = optionSemiGroup[String]

adderInt.add(Some(1), Some(2)) // Some(3)
adderString.add(Some("a"), Some("b")) // Some("ab")

// error: could not find implicit value for parameter adder: org.conbere.algebra.SemiGroup[(Int, Int)]
// this is an expected error since there is no defined SemiGroup for (Int,Int)
val adderTuple = optionSemiGroup[(Int,Int)]