This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Placeholder and parameters order

2 replies
Édson Rocha
Joined: 2009-03-16,
User offline. Last seen 1 year 47 weeks ago.
Hi,

About following code.

<scala>
object Placeholder {
 
  def filter(a: String, b: String, constraint: (String, String) => Boolean) = if(constraint(a, b)) println(a + " PASSED !")
                                                           else println(a + " FAILED !")

  def directContainsConstraint(s1: String, s2: String) = s1 contains s2
 
  def reverseContainsConstraint(s1: String, s2: String) = s2 contains s1
         
  def main(args : Array[String]) {
    filter("Rocha", "oc", _ contains _) // directContainsConstraint
    filter("oc", "Rocha", reverseContainsConstraint)  // How could I use this with placeholder ?
  }
}
</scala>

Is it possible ?

I'm asking out of cusiosity. :-)

Thanks in advance

--
Édson Rocha Patrício
www.verde.com.br
Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Placeholder and parameters order


On Tue, Mar 24, 2009 at 6:49 PM, Édson Rocha <edsonpatricio@gmail.com> wrote:
Hi,

About following code.

<scala>
object Placeholder {
 
  def filter(a: String, b: String, constraint: (String, String) => Boolean) = if(constraint(a, b)) println(a + " PASSED !")
                                                           else println(a + " FAILED !")

  def directContainsConstraint(s1: String, s2: String) = s1 contains s2
 
  def reverseContainsConstraint(s1: String, s2: String) = s2 contains s1
         
  def main(args : Array[String]) {
    filter("Rocha", "oc", _ contains _) // directContainsConstraint
    filter("oc", "Rocha", reverseContainsConstraint)  // How could I use this with placeholder ?

filter("oc", "Rocha", reverseContainsConstraint _ )
 
  }
}
</scala>

Is it possible ?

I'm asking out of cusiosity. :-)

Thanks in advance

--
Édson Rocha Patrício
www.verde.com.br



--
Viktor Klang
Senior Systems Analyst
Alex Boisvert
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Placeholder and parameters order
reverseContainsConstraint(_,_)


On Tue, Mar 24, 2009 at 10:49 AM, Édson Rocha <edsonpatricio@gmail.com> wrote:
Hi,

About following code.

<scala>
object Placeholder {
 
  def filter(a: String, b: String, constraint: (String, String) => Boolean) = if(constraint(a, b)) println(a + " PASSED !")
                                                           else println(a + " FAILED !")

  def directContainsConstraint(s1: String, s2: String) = s1 contains s2
 
  def reverseContainsConstraint(s1: String, s2: String) = s2 contains s1
         
  def main(args : Array[String]) {
    filter("Rocha", "oc", _ contains _) // directContainsConstraint
    filter("oc", "Rocha", reverseContainsConstraint)  // How could I use this with placeholder ?
  }
}
</scala>

Is it possible ?

I'm asking out of cusiosity. :-)

Thanks in advance

--
Édson Rocha Patrício
www.verde.com.br

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland