Aug. 6th, 2016

juan_gandhi: (VP)

  implicit class StreamOfResults[T](source: Stream[Result[T]]) {
    def |>[U](op: T ⇒ Result[U]) = source map (t ⇒ t flatMap op)
    def filter(p: T ⇒ Outcome) = source |> (x => p(x) andThen Good(x))
    def map[U](f: T ⇒ U) = source map (_ map f)
  }


  implicit class StreamOfResults[T](source: Stream[Result[T]]) {
    def |>[U](op: T ⇒ Result[U]) = source map (t ⇒ t flatMap op)
    def filter(p: T ⇒ Result[_]) = source |> (x ⇒ p(x) returning x)
    def map[U](f: T ⇒ U) = source map (_ map f)
  }


E.g. use case:
  // this method could be written in a couple of lines, but it's better to keep the details
  def streamOfNewEobSelectors(): StreamOfResults[Element] = {
    // this function pairs an html element with its content
    def withContent(e: Element): Result[(Element, String)] = e.outerHtml() map ((e, _))

    // here we have a stream of elements paired with their content
    val pairs: StreamOfResults[(Element, String)] = streamOfEobElements |> withContent

    // here we filter the stream, leaving only the elements containing new stuff
    // note that the stuff we don't need is not kicked out, it's labeled as bad with an explanation
    val newOnes: StreamOfResults[(Element, String)]] = pairs filter (p => isNewClaim(p._2))

    // here we forget the html
    newOnes map {case p:(Element, String) => p._1}
  }


Note that filter does not take a boolean, it takes an Outcome, which is a logical value, from the logic that I'm trying to work on. It's not Boolean.
juan_gandhi: (VP)
http://www.express.co.uk/news/world/696646/Thomas-Salbey-Munich-shooter-Ali-Sonboly-prosecution

In Germany, it is verboten to insult killers. And besides, the killer was a German, not a foreigner, so Thomas Salbey was wrong.

More, he threw at the terrorist a beer bottle. Das ist also verboten.

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

May 2025

S M T W T F S
    1 2 3
456 7 8 9 10
11 121314151617
181920 21 222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 22nd, 2025 09:37 pm
Powered by Dreamwidth Studios