val

Version, currently 0.1.02 versions

github.com/maiha/val.cr

Scala-ish lazy `val`, `var` for Crystal

1 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  val:
    github: maiha/val.cr
    version: ~> 0.1.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

val.cr Build Status

Scala-ish lazy val, var for Crystal.

  • crystal: 0.20.4
dependencies:
  val:
    github: maiha/val.cr
    version: 0.2.0

Usage

require "val"

class Foo
  val x = 1
  var y = "123"
  val z : Int32 = (a = [1]; a << 2; a.sum)

  val cached? = true
end

foo = Foo.new
foo.x         # => 1
foo.y = "xxx" # => "xxx"
foo.z         # => 3
foo.cached?   # => true

NOTE

val is almost same as getter except two points.

    1. getter with = evaulates code immediately, but val runs lazily.
    1. getter with = fails with multiple lines, but val accepts it.

Although getter with block runs lazily, block format has less readability than =.

Contributing

  1. Fork it ( https://github.com/maiha/val.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer