All Projects → InquisitivePenguin → Cascade

InquisitivePenguin / Cascade

Licence: mit
Dart-like cascade expressions in Rust

Programming Languages

rust
11053 projects
macro
33 projects

Projects that are alternatives of or similar to Cascade

C
Collection of various algorithms in mathematics, machine learning, computer science, physics, etc implemented in C for educational purposes.
Stars: ✭ 11,897 (+14063.1%)
Mutual labels:  hacktoberfest
Rws Ruby Sdk
Ruby Client for Rakuten Web Service
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Gitflux
Track your GitHub projects in InfluxDB and create beautiful graphs with Grafana
Stars: ✭ 84 (+0%)
Mutual labels:  hacktoberfest
Wiki
Archive of free60.org mediawiki
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Rstfinder
Fast Discourse Parser to find latent Rhetorical STructure (RST) in text.
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Pugxautocompleterbundle
Add an autocomplete field to your Symfony forms
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Monday
⚡️ A dev tool for microservice developers to run local applications and/or forward others from/to Kubernetes SSH or TCP
Stars: ✭ 1,246 (+1383.33%)
Mutual labels:  hacktoberfest
React Dashboard Design
⚡️ Implement of Vercel's Dashboard design in React
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Puppet Php
Generic Puppet module to manage PHP on many platforms
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Docker
Development repository for the docker cookbook
Stars: ✭ 1,253 (+1391.67%)
Mutual labels:  hacktoberfest
Node Mongodb Fixtures
🍏 Setup and tear down test fixtures with MongoDB.
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Ansible Playbook
An Ansible playbook for automated deployment of full-stack Plone servers.
Stars: ✭ 82 (-2.38%)
Mutual labels:  hacktoberfest
Paru
Feature packed AUR helper
Stars: ✭ 1,240 (+1376.19%)
Mutual labels:  hacktoberfest
Eleventy
A simpler static site generator. An alternative to Jekyll. Transforms a directory of templates (of varying types) into HTML.
Stars: ✭ 10,867 (+12836.9%)
Mutual labels:  hacktoberfest
Semana Hacktoberfest
🔥 Semana Hacktoberfest na Lukin Co. —— Quer participar da semana Hacktoberfest? Nós preparamos um guia especial para você!
Stars: ✭ 84 (+0%)
Mutual labels:  hacktoberfest
Bioconda Recipes
Conda recipes for the bioconda channel.
Stars: ✭ 1,247 (+1384.52%)
Mutual labels:  hacktoberfest
Radical.saga
A Light-Weight Access Layer for Distributed Computing Infrastructure and Reference Implementation of the SAGA Python Language Bindings.
Stars: ✭ 83 (-1.19%)
Mutual labels:  hacktoberfest
Awesome Laravel Zero
👋 START HERE! A curated list of Laravel Zero libraries, resources and projects
Stars: ✭ 84 (+0%)
Mutual labels:  hacktoberfest
Ritchie Formulas
This repository contains the community formulas that can be executed through Ritchie CLI once imported. This tool is an open source product that allows you to create, store and share any kind of automations, executing them through command lines, to run operations or start workflows ⚙️ 🖥 💡
Stars: ✭ 84 (+0%)
Mutual labels:  hacktoberfest
Algorithms Explanation
All Algorithms explained in simple language with examples and links to their implementation in various programming languages and other required resources.
Stars: ✭ 1,243 (+1379.76%)
Mutual labels:  hacktoberfest

cascade: Cascade expressions in Rust!

cascade is a macro library for Rust that makes it easy and ergonomic to use cascade-like expressions, similar to Dart.

#[macro_use]
extern crate cascade;

fn main() {
    let cascaded_list = cascade! {
      Vec::new();
      ..push("Cascades");
      ..push("reduce");
      ..push("boilerplate");
    };
    println!("{:?}", cascaded_list); // Will print '["Cascades", "reduce", "boilerplate"]'
}

This is only a small example of what cascade lets you do: the basic_cascades example in this repository covers the other cool features of the cascade! macro.

Why does this need to exist?

Cascades reduce boilerplate by eliminating the need for a 'temporary' variable when making several method calls in a row, and it also helps make struct member assignments look more ergonomic. For example:

#[macro_use]
extern crate cascade;

#[derive(Clone, Debug)]
struct Person {
  pub name: String,
  pub age: u32,
  pub height: u32,
  pub friend_names: Vec<String>
}

fn main() {
    // Without cascades
    let person = Person {
      name: "John Smith",
      age: 17,
      height: 68, // 5' 8"
      friend_names: {
        let mut tmp_names = Vec::new();
        tmp_names.push("James Smith".to_string());
        tmp_names.push("Bob Jones".to_string());
        tmp_names.push("Billy Jones".to_string());
        tmp_names
      }
    };
    // With cascades
    let person = Person {
      name: "John Smith",
      age: 17,
      height: 68,
      friend_names: cascade! {
        Vec::new();
        ..push("James Smith".to_string());
        ..push("Bob Jones".to_string());
        ..push("Billy Jones".to_string());
      }
    };
    // Cascades also let you do cool stuff like this
    let person_one_year_later = cascade! {
      person;
      ..age += 1;
      ..height += 2;
    };
}

In addition, cascades make it easier to design fluent interfaces. No more returning self with every single function!

Changelog

1.0.0: cascade has reached 1.0! Here are some of the cool new features and syntax changes made as a part of this:

  • The syntax for binding variables has been changed to use let syntax. This makes it more in-line with Rust syntax and also allows you to specify the type of a cascaded expression.
cascade! {
    // If you don't need to bind the statement to an identifier, you can use _
    let _: Vec<u32> = vec![1,2,3].into_iter().map(|x| x + 1).collect();
    ..push(1);
}
  • Statements no longer need | in front of them. You can just put the statement right in there, no prefix needed.
  • You can return expressions from cascades, just like normal Rust blocks. By default, cascades will already return the value of the cascaded variable. But if you want to return a custom expression, you can put it at the end of a cascade block, with no semicolon.
let has_more_than_three_elements = cascade! {
    let v = vec![1,2,3];
    ..push(4);
    v.len() > 3
};
println!("{}", cascade! {
    vec![1,2,3];
    ..push(4);
    ..into_iter().fold(0, |acc, x| acc + x)
});
  • Finally, you can have nested blocks within a cascade block. For example:
cascade! {
    vec![1,2,3];
    {
        let a = 1;
        ..push(a);
    };
}

I hope you enjoy cascade 1.0! Remember to leave any complaints or suggestions on the issue tracker.

0.1.3: The ? operator now works with cascades, for scenarios like this:

fn file_read() -> Result<SomeFileClass, ErrorMsg> {
    cascade! {
      SomeFileClass::create_file_reader("test.txt");
      ..load()?;
      ..check_validity()?;
    }
}

0.1.2: You can now chain methods together, like this:

fn chain_example() {
  cascade! {
    FnChainTest::new();
    ..chain().chain().chain();
  }
}

Credits

Written by Jackson Lewis

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