All Projects → xuwei-k → zeroapply

xuwei-k / zeroapply

Licence: other
zero cost Apply/Applicative syntax

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to zeroapply

owlet
Typed Spreadsheet UI library for ScalaJS
Stars: ✭ 40 (+233.33%)
Mutual labels:  applicative
elixir-control
An exploratory look into functors, applicatives, and monads for Elixir
Stars: ✭ 21 (+75%)
Mutual labels:  applicative
validation-selective
💂‍♂️ Lightweight pure validation based on Applicative and Selective functors
Stars: ✭ 61 (+408.33%)
Mutual labels:  applicative
kudojs
A utility library to write code in functional programming style in Javascript
Stars: ✭ 22 (+83.33%)
Mutual labels:  applicative
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (+158.33%)
Mutual labels:  applicative
Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+32933.33%)
Mutual labels:  applicative
Swiftz-Validation
A data structure for validations. It implements the applicative functor interface
Stars: ✭ 15 (+25%)
Mutual labels:  applicative
free-arrow
Implementation of the Free Arrow in Scala and other helpful tools for working with Arrows
Stars: ✭ 14 (+16.67%)
Mutual labels:  applicative
play2scalaz
Scalaz typeclasses <~> Playframework2 typeclasses
Stars: ✭ 14 (+16.67%)
Mutual labels:  applicative
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (+383.33%)
Mutual labels:  applicative

zeroapply

Zero Cost Apply/Applicative Syntax

example

zeroapply.OptionApply.apply3(Option(1), Option(2), Option(3))(_ + _ + _)

{
  val x0: _root_.scala.Option[Int] = scala.Option.apply[Int](1);
  if (x0.isEmpty)
    _root_.scala.None
  else
    {
      val x1: _root_.scala.Option[Int] = scala.Option.apply[Int](2);
      if (x1.isEmpty)
        _root_.scala.None
      else
        {
          val x2: _root_.scala.Option[Int] = scala.Option.apply[Int](3);
          if (x2.isEmpty)
            _root_.scala.None
          else
            _root_.scala.Some(x0.get.+(x1.get).+(x2.get))
        }
    }
}

scalaz.Equal and scalaz.Order macro

import scalaz._, std.AllInstances._

case class Foo[A, B](a: A, b: B, c: Int)

object Foo {
  implicit def instance[A: Order, B: Order]: Order[Foo[A, B]] =
    zeroapply.CaseClass.order[Foo[A, B]]
}

new Order[Foo[A, B]] {
  override def equalIsNatural =
    Equal[A].equalIsNatural && Equal[B].equalIsNatural && Equal[Int].equalIsNatural

  override def equal(x1: Foo[A, B], x2: Foo[A, B]) =
    Equal[A].equal(x1.a, x2.a) && Equal[B].equal(x1.b, x2.b) && Equal[Int].equal(x1.c, x2.c)

  override def order(x1: Foo[A, B], x2: Foo[A, B]) =
    Order[A].order(x1.a, x2.a) match {
      case Ordering.EQ =>
        Order[B].order(x1.b, x2.b) match {
          case Ordering.EQ => Order[Int].order(x1.c, x2.c)
          case z => z
        }
      case z =>
        z
    }
}

latest stable version

libraryDependencies += "com.github.xuwei-k" %% "zeroapply" % "0.5.0"
libraryDependencies += "com.github.xuwei-k" %% "zeroapply-scalaz" % "0.5.0"

for scalaz 7.2.x

https://github.com/xuwei-k/zeroapply/tree/0.2.x

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].