Skip to content

Instantly share code, notes, and snippets.

View alaz's full-sized avatar

Alexander Azarov alaz

View GitHub Profile
/**
* In reply to http://blog.xebia.com/2009/07/04/real-world-functional-programming-in-scala-comparing-java-clojure-and-scala/
*/
def opt[T](x: Seq[T]): Seq[T] = if (x == null) Nil else x
def indexed[T](coll: Seq[T]): Seq[(Int, T)] = {
val c = opt(coll)
List.range(0,c.length).zip(c.toList)
}
@alaz
alaz / IfLoggedIn.scala
Created June 16, 2009 14:35
Liftweb's IfLoggedIn implementation
/*
* IfLoggedIn implementation which redirects to the page a user was going to,
* after his/her successful login
*
* based on http://groups.google.com/group/liftweb/browse_thread/thread/bdd5accd4bb623c9/d56e054c4037470f ,
* works with ProtoUser out of the box
*/
// In SiteMap:
lazy val IfLoggedIn = If(User.loggedIn_? _, loginAndComeBack _)