This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait MonoidalLaw extends FunctorLaw { | |
def iso1[A] = new (A <=> (Unit, A)) { | |
def to = a => ((), a) | |
def from = { case (_, a) => a } | |
} | |
def iso2[A] = new (A <=> (A, Unit)) { | |
def to = a => (a, ()) | |
def from = { case (a, _) => a } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
class Message extends Backbone.Model | |
class MessageList extends Backbone.Collection | |
url: "/messages" | |
Messages = new MessageList | |
class MessageView extends Backbone.View | |
tagName: "tr" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.hexx.messageboard | |
import java.util.Date | |
import unfiltered.request._ | |
import unfiltered.response._ | |
import com.github.hexx.gaeds.{ Datastore, Mapper, Property } | |
import com.github.hexx.gaeds.Property._ | |
import net.liftweb.json._ | |
class Message( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Model to JSON | |
(new Person("John", 13)).toJson // -> {"name":"John","age":13} | |
// JSON to Model | |
Person.fromJson("""{"name":"John","age":13}""") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Low-Level API | |
val q = new Query("Person") | |
val f1 = new FilterPredicate("age", GREATER_THAN_OR_EQUAL, 10) | |
val f2 = new FilterPredicate("age", LESS_THAN_OR_EQUAL, 20) | |
q.setFilter(CompositeFilterOperator.and(f1, f2)) | |
DatastoreServiceFactory.getDatastoreService.prepare(q).asIterator | |
// Gaeds | |
Person.query.filter(p => (p.age #>= 10) and (p.age #<= 20)).asIterator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(s: String): Kleisli[Option, Map[String, String], String] = Kleisli(_ get s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val h: String => Option[String] = _ |> f >>= g |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get[K, V](k: K)(m: Map[K, V]): String \?/ V = | |
try { | |
m(k).success | |
} catch { | |
case e: Throwable => e.getMessage.failure | |
} | |
def user(m: Map[String, String]): NonEmptyList[String] \?/ User = | |
(get("id")(m).toValidationNEL |@| get("age")(m).flatMap(parseInt).toValidationNEL)((id, age) => User(id, age.toInt)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def BuyAndCheck(book: Book): StateT[Option, Person, Unit] = | |
for { | |
_ <- buy(book).lift[Option] | |
_ <- check | |
} yield () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Macros._ | |
object Test extends App { | |
val a = 28 | |
println("non-hygienic: " + nonHygienicA()) | |
println("hygienic: " + hygienicA()) | |
} |