Skip to content

a cross-platform C++ library for functional programming

License

Notifications You must be signed in to change notification settings

CatalinMihaiGhita/libwave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to libWave

A C++ library for asynchronous functional programming.

All you need is the >>= operator.

Start with the loop

int main()
{
  using namespace wave;
  loop main_loop;
  idle{} >>= { std::cout << "Hello World!"; };
  return 0;
}

Idling

idle{2}
>>= ${ std::cout << "This message is twice!"; };

Timer

timer{1000}
>>= ${ std::cout << "One second passed!"; };

Composing

idle{}
>>= ${ return 1000; }
>>= $(int timeout) { return timer{timeout}; }
>>= ${ std::cout << "Maybe one second passed!"; };

TCP server

tcp_server server{ 5000 };
std::cout << "Listening..." << std::endl;
server >>= ${
  std::cout << "Client connected" << std::endl;
  auto client = server.accept();
  client << "I send you 50$";
  return client;
} >>= $(std::string data) {
  std::cout << "Client sent me: " << data << std::endl;
};

TCP client

tcp_client client{ "127.0.0.1", 5000 };
client.connected() >>= ${
  std::cout << "Client connected" << std::endl;
  client << "I send you 100$";
  return client;
} >>= $(std::string data) {
  std::cout << "Server sent me: " << data << std::endl;
};

Spawning a process

process<stdout_pipe> ls{"ls", "-l", "/home"};
ls.stdout() >>= $(std::string output) {
  std::cout << output;
};

About

a cross-platform C++ library for functional programming

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published