All Projects → lazebny → ramda-ruby

lazebny / ramda-ruby

Licence: MIT License
Ruby port of http://ramdajs.com

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ramda-ruby

Zebras
Data analysis library for JavaScript built with Ramda
Stars: ✭ 192 (+88.24%)
Mutual labels:  ramda
R.apex
Functional utility library for Apex
Stars: ✭ 80 (-21.57%)
Mutual labels:  ramda
ramda
🦋Practical functional Go
Stars: ✭ 14 (-86.27%)
Mutual labels:  ramda
ramda.py
Python clone of Ramda.js
Stars: ✭ 64 (-37.25%)
Mutual labels:  ramda
learn-ramda
🐏 Learn ramda, the interactive way
Stars: ✭ 84 (-17.65%)
Mutual labels:  ramda
spellbook
Spellbook is a bookmark extension for Chrome and Firefox
Stars: ✭ 19 (-81.37%)
Mutual labels:  ramda
Ramda Extension
🤘Utility library for functional JavaScript. With ❤️ to Ramda.
Stars: ✭ 139 (+36.27%)
Mutual labels:  ramda
functional-programming-with-ramda
Demo for Functional Programming with Ramda workshop at DeveloperWeek 2018
Stars: ✭ 21 (-79.41%)
Mutual labels:  ramda
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (-82.35%)
Mutual labels:  ramda
utils.js
Fast, small and purely functional utility library
Stars: ✭ 132 (+29.41%)
Mutual labels:  ramda
Fae
A functional module for Deno inspired from Ramda.
Stars: ✭ 44 (-56.86%)
Mutual labels:  ramda
mern-boilerplate
A Full MERN Stack Boilerplate for Web Apps including a local authentication system. Uses React, Express.js, MongoDB, Redux, Passport.js, Webpack, Testing, and more.
Stars: ✭ 211 (+106.86%)
Mutual labels:  ramda
fp-ts-ramda
Ramda functions reimplemented in fp-ts
Stars: ✭ 129 (+26.47%)
Mutual labels:  ramda
ramdatutorial
Companion source code for a Ramda Tutorial
Stars: ✭ 24 (-76.47%)
Mutual labels:  ramda
nebuchadnezzar
on the way to cleanest react architechture
Stars: ✭ 15 (-85.29%)
Mutual labels:  ramda
Rambdax
Extended version of Rambda
Stars: ✭ 148 (+45.1%)
Mutual labels:  ramda
validarium
🛡Agnostic validation library for JavaScript applications.
Stars: ✭ 29 (-71.57%)
Mutual labels:  ramda
react-boilerplate
A Simple React Boilerplate for Web Apps. Uses React, Redux, Webpack, Hot Reloading for JS and CSS, Testing, and more.
Stars: ✭ 18 (-82.35%)
Mutual labels:  ramda
photoshop-react-redux-ramda
🎨😱💀⚛️
Stars: ✭ 24 (-76.47%)
Mutual labels:  ramda
ramdasauce
Ramda smothered in saucy helpers.
Stars: ✭ 69 (-32.35%)
Mutual labels:  ramda

Ramda Ruby

This is a ruby version of Ramda Js library.

Gem Version Functions Travis badge AppVeyor status Coverage Status Code Climate Badge Inch CI Dependency Status License

Information

This library uses some stuff like curry and __ which reduces performance. Please review benchmarks section.

Installation

Add this line to your application's Gemfile:

gem 'ramda-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ramda-ruby

And then require:

require 'ramda'

Documentation

You can use Ramda docs as a documentation or to check Ruby examples.

Algebraic structures

Methods which supports algebraic types:

  • ap
  • both
  • chain
  • complement
  • either
  • lift
  • lift_n
  • map
  • pluck

Supported libraries (comparison):

dry-monads

works with ruby >= 2.1

kleisli works from this fork:

gem 'kleisli', git: '[email protected]:lazebny/kleisli.git', branch: 'ramda-ruby'

Differences:

Usage

Pointless Style:

  R = Ramda

  players = [
    { name: 'Andrey', score: 100 },
    { name: 'Ivan', score: 200 },
    { name: 'Masha', score: 150 }
  ]

  best_player = R.pipe(R.sort_by(R.prop(:score)), R.reverse, R.head, R.prop(:name))
  best_player.call(players) # Ivan

Placeholder:

  reset_to_default = R.merge(R.__, x: 0)
  reset_to_default.call(x: 5, y: 2) # { x: 0, y: 2 }

Transducers:

  appender = R.flip(R.append)

  xform = R.map(R.add(10))
  R.transduce(xform, appender, [], [1, 2, 3, 4]) # [11, 12, 13, 14]

  xform = R.filter(:odd?.to_proc)
  R.transduce(xform, appender, [], [1, 2, 3, 4]) # [1, 3]

  xform = R.compose(R.map(R.add(10)), R.take(2))
  R.transduce(xform, appender, [], [1, 2, 3, 4]) # [11, 12]

  xform = R.compose(R.filter(:odd?.to_proc), R.take(2))
  R.transduce(xform, R.add, 100, [1, 2, 3, 4, 5]) # 104)
  R.transduce(xform, appender, [], [1, 2, 3, 4, 5]) # [1, 3])
  R.into([], xform, [1, 2, 3, 4, 5]) # [1, 3])

With algebraic structures:

  # ap
  R.ap(R.ap(Maybe.of(R.add), Maybe.of(3)), Maybe.of(5)) # Some(8)

  # chain
  R.chain(->(x) { Maybe.of(R.add(5, x)) }, Maybe.of(3)) # Some(8)

  # map
  R.map(R.add(3), Maybe.of(5)) # Some(8)

  # lift
  add_m = R.lift(R.add)
  add_m.call(Maybe.of(3), Maybe.of(5)) # Some(8)

  # lift_n
  add_m = R.lift_n(3, -> (a, b, c) { a + b + c })
  add_m.call(Maybe.of(3), Maybe.of(5), Maybe.of(10)) # Some(18)

Change exceptions handler:

  # To use a default 'with_narrow' handler:
  Ramda.exception_handler = nil
  # the same as:
  Ramda.exception_handler = -> Ramda::ExceptionHandler.method(:with_narrow)

  # Set a custom handler:
  Ramda.exception_handler = -> (e, _method_name) { raise e, e.exception, e.backtrace }
  # the same as:
  Ramda.exception_handler = -> Ramda::ExceptionHandler.method(:default)

Ramda in debug mode shows calls trace. Notice: trace is shown only for Ramda functions and not for regular procs. If you want to show a whole trace you can wrap your proc in Ramda.curry function (pleaes see example below).

Enable debug mode:

  Ramda.debug_mode = true

  # Example:

  Ramda.filter(Ramda.curry(:even?.to_proc, [1, 2, 3, 4])

  # -> curry(#<Proc:0x...@/srv/app/spec/ramda/list_spec.rb:130 (lambda)>) # #<Proc:0x... (lambda)>
  # -> curry(1) # false
  # -> curry(2) # true
  # -> curry(3) # false
  # -> curry(4) # true
  # -> filter(#<Proc:0x0055ff3fad4640 (lambda)>, 1, 2, 3, 4) # [2, 4]

Resources

Benchmarks

Send all results to STDOUT

bundle exec rake ramda:run_benchmark

Send one function type results to STDOUT

bundle exec rake ramda:run_benchmark[bench/list/*]

Update all files in bench_results

bundle exec rake ramda:run_benchmark_to_file

Update one type of function in bench_results

bundle exec rake ramda:run_benchmark_to_file[bench/list/*]

Development

You can use either regular approach with installing gems on local machine or with docker-compose which is handy when you are playing with ruby versions.

With docker-compose:

  1. Install Docker
  2. Install Docker Compose
  3. Run tests
touch .bashrc.docker .pry_history.docker
docker-compose run --rm app bash
bundle
rspec

To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make changes
  4. Check with Rubocop and resolve all issues(rubocop -aD)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

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].