Git Product home page Git Product logo

monocle's Introduction

Monocle Logo

All documentation is available on Monocle website.

monocle's People

Contributors

adamw avatar aoiroaoino avatar armanbilge avatar cquiroz avatar cvogt avatar dependabot[bot] avatar dwijnand avatar fthomas avatar gpampara avatar jan0sch avatar japgolly avatar jbgi avatar jule64 avatar julien-truffaut avatar kenbot avatar kubukoz avatar mdulac avatar n4to4 avatar nightra avatar puffnfresh avatar rossh avatar scala-steward avatar scala-steward-bot avatar sellout avatar sethtisue avatar sh0hei avatar valydia avatar xuwei-k avatar yilinwei avatar zaneli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

monocle's Issues

Help needed to execute the README in the REPL

I have cloned the project.
run sbt

$ project core
$ console
> import lens.Lens
> case class Location(latitude: Long, longitude: Long)
> case class Address(city: String, postcode: String, location: Location)
> case class Person(name: String, age: Int, address: Address)
> object AddressLens  extends Lens[Person, Address]
<console>:14: error: object creation impossible, since:
it has 2 unimplemented members.
/** As seen from object AddressLens, the missing signatures are as follows.
 *  For convenience, these are usable as stub implementations.
 */
  def get(from: Person): Address = ???
  def lift[F[_]](from: Person,f: Address => F[Address])(implicit evidence$1: scalaz.Functor[F]): F[Person] = ???

       object AddressLens  extends Lens[Person, Address]
              ^

What am I doing wrong?

If I can run it myself I can fork and make a pull request with all the issues I find in the README.

Improve running time of functions.

Head for example takes O(n) time, instead O(1) for most cases.

One of the big causes for that is headOption in Fold.

I'll search for more of these soon.

Advertise compile-time checking of case class field names

I think Monocle's documentation may benefit from mentioning that strings for field names are checked for correctness at compile-time; for instance "_health" matches the field name in Character, from the Readme example val health = Macro.mkLens[Character, Int]("_health")

It may help to attract the "Strongly-typed not Stringly-typed" crowd :)

Move to SBT 0.13.2

We should move to SBT 0.13.2, and enable name hashing, resulting in faster compilation.

ambiguous implicit error while playing with options and case classes

I defined a case class like this,

case class User(name: String, pass: String)

and I wanted to uppercase the name of an Option[User]. When I tried something like this:

Option(User("", "")) |->> each |->> _name ...

It worked without problems but then I tried:

Some(User("", "")) |->> each |->> _name ...

and I got the following compile error:

[error]  both method mapEach in trait EachInstances of type [K, V]=> monocle.function.Each[Map[K,V],V]
[error]  and method optEach in trait EachInstances of type [A]=> monocle.function.Each[Option[A],A]
[error]  match expected type monocle.function.Each[S,A]
[error]   println(user |->> each |->> _name modify (_.toUpperCase))

Check this repository for further information:

https://github.com/lvicentesanchez/monocle-option-some

Lens example in the readme

I think we should put a lens example in the readme to give the guys a better idea of what the project all about.

Coding Style

We should decide where to put our braces, what our indent size would be, how we would name classes, variables, and functions, and so forth. We should encoded these rules into the code formatter of our IDE's and stick with them.

Define stackoverflow tag

We should probably define a stackoverflow tag so that users can post questions and we can easily find them. It looks like 'monocle' has already been defined, so maybe 'scala-monocle'.

Once a decision has been made, we should add it to the readme.

Solodify package/import structure for functions.

Each function should be in it's own package with a package object for importing,
to avoid mess created by many class declarations for implicits.

There should be a unified functions._ import.

Shall we add a Prism without Re?

When we compose a Lens with a Prism we obtain a Traversal, so we lose the knowledge that we are zooming to 0-1 object instead of a 0-n objects (a Traversal).

trait Traversal[S, T, A, B]

trait NewConcept[S, T, A, B] extends Traversal[S, T, A, B] {
   def getOption(from: S): A
}

trait Lens[S, T, A, B] extends NewConcept[S, T, A, B]

trait Prism[S, T, A, B] extends NewConcept[S, T, A, B]{
  def re: Getter[B, T]
  def reverseGet(from: B): T
}

This NewConcept should respect Traversal laws and getAll.size <= 1

Build a Traversal from getAll and setAll

The Lens companion object has:

def apply[S, T, A, B](_get: S => A, _set: (S, B) => T): Lens[S, T, A, B]

so it would seem that it could be useful for Traversal to have something like:

def apply[S, T, A, B](_getAll: S => List[A], _setAll: (S, List[B] => T): Traversal[S, T, A, B]

Actually, since this is something of a convenience method, it might be better to generalize it by allowing anything that can be traversed instead of just List:

def apply[R[_]: Traverse, S, T, A, B](_getAll: S => R[A], _setAll: (S, R[B]) => T): Traversal[S, T, A, B]

Anyway, I'll have a pull request along shortly and you can decide whether this makes any sense :)

Create lens for head and tail of List

head[A] : SimpleLens[List[A], Option[A]]
head.get(List(1,2,3)) == Some(1)
head.set(List(1,2,3), Some(0)) == List(0,2,3)
head.set(List(1,2,3), None) == List(2,3) // delete
head.set(Nil, Some(2)) == Nil

Review syntax

I am not fan of oo as synonym for compose and I don't like that we need to define a new operator to create an AppliedLens (>-), AppliedTraversal (>--) and so on.

Mailing list

We should create a mailing list. Maybe a google group?

Create Init

Same than tail except that it a Traversal toward all elements except the last one

Does not compile in Eclipse

@acachada mentioned that eclipse raised several compiler issues. At least, one is valid about the use of Macro inside of core should be forbidden.

README review

Hi Julien,

I see you are making it really nice and I decided to help out a bit.

I try to follow the README using the REPL and I find some minor issues.
case class Person(name: String, age: Int, address: Address)
case class Address(city: String, postcode: String, location: Location)
case class Location(latitude: Long, longitude: Long)

The order would be inverse in the REPL
case class Location(latitude: Long, longitude: Long)
case class Address(city: String, postcode: String, location: Location)
case class Person(name: String, age: Int, address: Address)

In the first example the "GET" I believe you are using a previous syntax
Person2CityLens.get(person, "Paris")

Probably should be
(AddressLens >- CityLens).get(person)

Monocle logo

@laytona We need a logo with a guy wearing a monocle and perhaps and moustache and a top hat.

SimplePrism reverseSet & reverseModify

  "One can get the next/previous character with the safeCast[Char,Int] prism" in {
    safeCast[Int,Char].getOption(safeCast[Int,Char].reverseGet('a') + 1) shouldEqual Some('b')
    safeCast[Int,Char].reverseModify('a', _ + 1) shouldEqual Some('b')
    safeCast[Int,Char].reverseModify('z', _ - 1) shouldEqual Some('y')
  }

We could also define Char <-> Short Iso.

SimplePrism[A,B] represents a one-on-one function A => B and it's partial inverse function B => A.
We might get a couple of interesting things from limiting to SimplePrism.

Lighting Talk

Not a code issue, but it might be a good idea to do a lighting talk at an LSUG event. I'm sure if we speak to Andy, he would be up for it. The question is, what to include? Maybe just some features, examples and the diagram @julien-truffaut has done.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.