Lzok / fp-101

Basic functional programming exercises with TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeScript/JavaScript functional 101

The aim of this repository is to help you get used to the functional programming style. It is a collection of exercises, with automatic tests that will check your solutions. It does not explain functional concepts. It is also introductory, so advanced topics won't be covered.

The exercises can be solved using TypeScript or JavaScript (but I strongly recommend you to use TypeScript).

You will find the exercises here.

Is this guide for me?

If you want to start with functional programming and you know at least a little bit of JavaScript or TypeScript, then yes!

Setup

Running the tests

You can run all the tests with npm t or run an utilitary tool (npm run learn or ./learn) to just run the tests for the exercise you are interested in (recommended option).

Following the rules

It is really important to follow "the rules" when solving the exercises. They are there to help you solve the problems in a "functional way".

Solving the exercises

You will find the exercises here.

You can find the exercise's tests into src/exercises directory. They are sorted in the same way than in the exercises page. To solve one exercise, you should create a file next to the test file with the same name, but without the .test part. The first exercise (id) is already solved as an example. In that file you should define the function that solves the problem and export it. If it's well done, the tests should pass for that exercise.

For some exercises, you can reuse the solutions you've already done. You can (and should) also use the functions from @utils.

Solving the exercises with JS

Even though I recommend to use TypeScript, you can solve the exercises using JavaScript. Just use the .js extension instead of the .ts one for your solutions. Also, remember to set the property you want to export to module.exports. For instance, the first exercise would be like this solved with JavaScript (into a src/exercises/01-id/id.js file):

const id = x => x;

module.exports = {
	id
};

@utils

There is a collection of utility funtions called "@utils". You can import them by doing (for example):

import { add } from `@utils`;

The functions there are all curried. You can find the source code of them at src/utils directory.

Solutions

The solutions to the exercises are uploaded to the solutions branch, you can take a peek to them if you wish (though I recommend you to try solving the problems by yourself first).

Contributing

All the contributions (issues reporting, PRs, difussion, etc.) will be welcome.

License

MIT License.

About

Basic functional programming exercises with TypeScript

License:MIT License


Languages

Language:TypeScript 81.3%Language:JavaScript 15.0%Language:Shell 3.7%