|
Lift Framework example source code file (HList.scala)
The Lift Framework HList.scala source code/* * Copyright 2010-2011 WorldWide Conferencing, LLC * * 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. */ package net.liftweb package common /** * Support for heterogenious lists, aka <a href="http://apocalisp.wordpress.com/2010/07/06/type-level-programming-in-scala-part-6a-heterogeneous-list%C2%A0basics/">HLists * */ object HLists { /** * The trait that defines HLists */ sealed trait HList { type Head type Tail <: HList /** * The length of the HList */ def length: Int } /** * The last element of an HList */ final class HNil extends HList { type Head = Nothing type Tail = HNil /** * Create a new HList based on this node */ def :+:[T](v : T) = HCons(v, this) override def toString = "HNil" /** * The length of the HList */ def length = 0 } /** * The HNil singleton */ val HNil = new HNil() /** * The HList cons cell */ final case class HCons[H, T <: HList](head : H, tail : T) extends HList { type This = HCons[H, T] type Head = H type Tail = T /** * Create a new HList based on this node */ def :+:[T](v : T) = HCons(v, this) override def toString = head + " :+: " + tail /** * The length of the HList */ def length = 1 + tail.length } type :+:[H, T <: HList] = HCons[H, T] object :+: { def unapply[H, T <: HList](in: HCons[H, T]): Option[(H, T)] = Some(in.head, in.tail) } } Other Lift Framework examples (source code examples)Here is a short list of links related to this Lift Framework HList.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.