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

com.stackmob.lucid.package.scala Maven / Gradle / Ivy

The newest version!
package com.stackmob

/**
 * Copyright 2012-2013 StackMob
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import scalaz._
import Scalaz._

package object lucid {

  def trimPathPrefix(pathPrefix: String): String = {
    ~Option(pathPrefix).flatMap { p =>
      val prefix = p.dropWhile(_ === '/').reverse.dropWhile(_ === '/').reverse
      (prefix.length > 0).option("/" + prefix)
    }
  }

  def validating[A](a: => A): Validation[Throwable, A] = a.pure[Function0].throws

  implicit def validationToValidationW[E, A](v: Validation[E, A]): ValidationW[E, A] = new ValidationW[E, A] {
    override val value = v
  }

  trait ValidationW[E, A] extends NewType[Validation[E, A]] {
    def mapFailure[EE](fn: E => EE): Validation[EE, A] = value match {
      case Success(s) => s.success
      case Failure(t) => fn(t).fail
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy