All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jaskell.parsec.Is.scala Maven / Gradle / Ivy

package jaskell.parsec

import scala.util.{Success, Try}

/**
 * TODO
 *
 * @author mars
 * @version 1.0.0
 * @since 2020/07/23 14:18
 */
class Is[T](val predicate: Function[T, Boolean]) extends Parsec[T, T] {
  def apply(s: State[T]): Try[T] = {
    s.next().flatMap(item => {
      if(predicate(item)) {
        Success(item)
      } else {
        s.trap(s"expect anything pass predicate check but get $item")
      }
    })
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy