Giter Site home page Giter Site logo

guangie88 / rustfp Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 1.0 339 KB

C++ implementation of Rust Option/Result and Iterator.

License: MIT License

C++ 98.43% CMake 1.25% C 0.32%
cpp cpp14 rust functional-programming monad monadic monadic-optionals monadic-result iterator

rustfp's Introduction

rustfp

Build Status Build status codecov

Overview

C++14 implementation of Rust Option/Result (monads) and Iterator concepts, useful for expressing items and result manipulation in a more functional style.

Currently tested to be compiling on g++-5 and above, MSVC2015 and above. clang should work as well, as long as the version supports C++14.

Repository Checkout

For Git version 1.6.5 or later:

git clone --recursive https://github.com/guangie88/rustfp.git

For already cloned repository or older Git version:

git clone https://github.com/guangie88/rustfp.git
git submodule update --init --recursive

Compilation and Installation

The solution uses CMake (at least version 3.6) for compilation and installation. To enable unit tests to be compiled for rustfp, add -DRUSTFP_INCLUDE_UNIT_TESTS=ON during the CMake configuration step.

Windows Generator Names

  • MSVC

    • 32-bit

      • MSVC2015: Visual Studio 14
      • MSVC2017: Visual Studio 15
    • 64-bit

      • MSVC2015: Visual Studio 14 Win64
      • MSVC2017: Visual Studio 15 Win64

Windows Compilation

Debug and Release Compilation Example

mkdir build
cd build
cmake .. -G "Visual Studio 14 Win64" -DCMAKE_INSTALL_PREFIX:PATH=install
cmake --build . --config debug
cmake --build . --config release --target install

Linux Generator Names

For Linux, simply run export CC=<path-to-desired-CC-compiler>; export CXX=<path-to-desired-CXX-compiler> before running the CMake commands. As such, there should be no need to set -G <generator-name>.

Example

export CC=/usr/bin/gcc-5; export CXX=/usr/bin/g++-5

Linux Compilation

Note that gcc requires the build type to be specified at the CMake configuration step.

Debug Compilation Example

mkdir build-debug
cd build-debug
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake --build .

Release Compilation Example

mkdir build-release
cd build-release
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=install
cmake --build . --target install

Installation Extraction

For the header files that are required to be included in other solutions, simply extract out the following directories in build/install/include into your other desired include directory:

  • nonstd
  • mpark
  • rustfp

Usage Examples

#include "rustfp/collect.h"
#include "rustfp/iter.h"
#include "rustfp/map.h"

#include <cassert>
#include <string>
#include <vector>

int main() {
    const std::vector<int> v_int{0, 1, 2};

    // rustfp::iter works differently from C++ iterator.
    // containers with proper begin/cbegin and end/cend
    // has to be wrapped by rustfp::iter before any of
    // the FP operations (e.g. map, filter, fold) can be
    // used.

    const auto v_str = rustfp::iter(v_int)
        | rustfp::map([](const auto &v) {
            // v is of const int & type
            return std::to_string(v);
        })
        | rustfp::collect<std::vector<std::string>>();

    assert(v_str[0] == "0");
    assert(v_str[1] == "1");
    assert(v_str[2] == "2");
}

rustfp's People

Contributors

guangie88 avatar

Stargazers

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

Watchers

 avatar  avatar

Forkers

guhwanbae

rustfp's Issues

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.