Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Last active September 10, 2023 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ongaeshi/e0d7134c0dcc415b047c2f52740cf78c to your computer and use it in GitHub Desktop.
Save ongaeshi/e0d7134c0dcc415b047c2f52740cf78c to your computer and use it in GitHub Desktop.
scala> def largerThan(n: Int)(i: Int): Boolean = i > n
def largerThan(n: Int)(i: Int): Boolean
scala> largerThan(4)
val res1: Int => Boolean = Lambda$6155/0x000001919e039400@372eb77
scala> largerThan(4)(5)
val res2: Boolean = true
scala> List(5,1,2,4,0).filter(largerThan(4))
val res3: List[Int] = List(5)
scala> def divisibleBy(n: Int)(i: Int): Boolean = i % n == 0
def divisibleBy(n: Int)(i: Int): Boolean
scala> List(5, 1, 2, 4, 15).filter(divisibleBy(5))
val res4: List[Int] = List(5, 15)
scala> def shorterThan(n: Int)(s: String): Boolean = s.length() < n
def shorterThan(n: Int)(s: String): Boolean
scala> List("scala", "ada").filter(shorterThan(4))
val res5: List[String] = List(ada)
scala> def hasS(n: Int)(s: String): Boolean = s.length() - s.replaceAll("s", "").length() >= n
def hasS(n: Int)(s: String): Boolean
scala> List("rust", "ada").filter(hasS(2))
val res6: List[String] = List()
scala> List("rust", "ada").filter(hasS(1))
val res7: List[String] = List(rust)
scala> def containsS(n: Int)(s: String): Boolean = s.length() - s.replaceAll("s", "").length() > n
def containsS(n: Int)(s: String): Boolean
scala> List("rust", "ada").filter(containsS(2))
val res8: List[String] = List()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment