1

This is a follow-up to my previous question:

Suppose I have a few functions that return scalaz.Validaton:

type Status[A] = ValidationNel[String, A]

val isPositive: Int => Status[Int] = 
  x => if (x > 0) x.success else s"$x not positive".failureNel

val isNegative: Int => Status[Int] = 
  x => if (x < 0) x.success else s"$x not negative".failureNel

I can write a new function makeX

case class X(x1: Int, // should be positive
             x2: Int, // should be positive
             x3: Int) // should be negative

val makeX: (Int, Int, Int) => Status[X] = (x1, x2, x3) => 
  (isPositive(x1) |@| isPositive(x2) |@| isNegative(x3)) (X.apply _)

My question is: How to write makeX in point-free style

Community
  • 1
  • 1
Michael
  • 41,026
  • 70
  • 193
  • 341

1 Answers1

1

Here's a funky way to make it pointfree:

val makeX: (Int, Int, Int) => Status[X] = isPositive(_) |@| isPositive(_) |@| isNegative(_) apply X
beefyhalo
  • 1,691
  • 2
  • 21
  • 33