• Stars
    star
    418
  • Rank 103,620 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An Elixir Flavored Language for the Browser

RedScript 2.0

Project is Deprecated

After the recent changes in ReasonML there really isn't a valid reason to keep working on this project anymore as ReasonML does a much better job, provides more safety, and in my opinion has an even nicer syntax and developer exerience.

https://reasonml.github.io/


It's like CoffeeScript but immutable & functional

Why use yet another sugar for JavaScript? Here are some features that go beyond a nice sytax:

  • Immutable data
  • Pattern matching in module functions
  • No support for classes or OO forces a functional (yet pragmatic) coding style
  • Think in data transformations with the pipe operator |> (like Unix pipes, F# & Elixir)
  • Standard Lib that utilizes Lodash (patched to be immutable)
  • **CLI for compiling and creating projects **
  • Compile time type inference checking using Flow

RedScript was created to provide a first class functional experience in the browser. I was tired of trying to coerce JavaScript into being a functional language (by not using the bad parts by convention and using other libs).

It is inspired from Elixir but it does not have all of the features (ElixirScript aims to do this). Our main goal is to provide easy interoperability with other JavaScript libraries (like CoffeeScript, not like Elm) while still providing a first class functional experience in JavaScript.

To Install Globally and Run

# 2.0 is a work in progress, not all features implemented
# Note, this compiler is just a prototype and is not production ready
sudo npm install -g redscript
redscript watch [fileName fileName2]

Think in pipes instead of nesting functions

# use functions like unix pipe

"hello world " |> String.trim |> String.uppercase
#>>> "HELLO WORLD"

["foo", "bar", " baz"]
  |> Enum.map((x) -> String.upcase(x))
  |> inspect()
  |> take(2)

# inspect-output ["FOO", "BAR", "BAZ"]
# >>> ["FOO", "BAR"]

Immutable Data (not currently supported)

Mutable data in JavaScript can lead to tricky bugs

state = {bar: 3}

# throws an error
state.bar = 10

# create copy and merge in new key/values
new_state = {state <- foo: 2, baz: 4}
# >> {foo: 2, bar: 3, baz: 4}

list = [1, 2]             
list_two = [5, 6]
combined_list = [list <- 3, 4, list_two]

Modules exposing public functions (no classes!)

import {some_js_function} from "some-js-or-redscript-module"

defmodule PhoneUtils do
  def normalize_number(number) do
    return number
    |> imported_func('-')
    |> remove_char(' ')  
    |> remove_us_code    
  end                    

  def remove_us_code(str) do
    return str.replace(/^+1/g, '')
  end                             

  defp remove_char(str, char) do  
    return str.replace(/\s/g, '') 
  end
end

Built In Support For Lo-Dash

Just snake case the API you already know. To keep things tidy, functions are placed in namespaces. Collections are in the Enum namespace, Array in List, Strings are in a String namespace, etc... (however you could still just import lo-dash ES6 style to remove the namespace).

                                                 # or use pipe operator with lo-dash
List.take(["a", "b", "c"], 2)                    ["a", "b", "c"] |> List.take(2)
#>> ["a", "b"]

List.flatten_deep([1, [2, 3, [4]]])              [1, [2, 3, [4]]] |> List.flatten_deep
#>> [1, 2, 3, 4]

Enum.reject([1, 2, 3, 4], (n) => n % 2 == 0)      [1, 2, 3, 4] |> Enum.reject((n) => n % 2 == 0)
#>> [1, 3]

Pattern Matching Coming Soon!

Pattern matching can eliminate the use of if statements and can really clean up code. This is on the backlog but PRs are welcome!

defmodule MyUtils do
  def count([]) do
    return 0
  end

  def count([head|tail]) do
    return 1 + count(tail)
  end
end

Full Syntax

More Repositories

1

react-ive-meteor

Demo app of React and Meteor using a social feed
JavaScript
243
star
2

Retina-Sprites-for-Compass

A mixin for creating retina sprites with hover & active states
CSS
233
star
3

meteor-react-boilerplate

A starter project for React & Meteor
JavaScript
168
star
4

meteor-flux-leaderboard

Flux Example with React & Meteor
JavaScript
131
star
5

parse-form

A micro library & Meteor package used to parse and manipulate forms
JavaScript
71
star
6

meteor-redux-example

Redux for Blaze
JavaScript
69
star
7

meteor-generate

Meteor Generate - A Rails Inspired File Generator for Meteor
JavaScript
65
star
8

meteor_elixir

An experiment to eliminate bottlenecks in Meteor
JavaScript
45
star
9

Meteor-RethinkDB-GraphQL

A Meteor and RethinkDB Example Using GraphQL
JavaScript
44
star
10

react-meteor-tests

React Unit Tests in Meteor
JavaScript
39
star
11

meteor-phonegap-oauth

Fixes how Meteor handles OAuth popups on PhoneGap/fullscreen
JavaScript
33
star
12

phoenix-rethinkdb-example

Example App with RethinkDB
JavaScript
22
star
13

Meteor-Cordova-Status

Reactive Cordova Status & Meteor Disconnect/Reconnect Handling
JavaScript
18
star
14

awesome-stack

Elixir
17
star
15

life-changing-programming-lessons

A collection of things I wish I knew 20 years ago
16
star
16

simple-redux-react

A wrapper to get Redux, React, react-router-redux, redux-devtools going in a few lines
JavaScript
16
star
17

meteor-flux-helpers

Meteor package with general flux helpers
JavaScript
15
star
18

backbone-fill-collection

Fill collections with mock data with every fetch.
JavaScript
11
star
19

validate-form

Meteor form validation micro library
JavaScript
11
star
20

reason-simple-form-example

Create React App Example
OCaml
10
star
21

meteor-react-accounts

A set of compossible components to sign in / login / signin / reset password / dropdown
JavaScript
9
star
22

pipes-js

Pipe operators in JS like Elm / Elixir / F#
8
star
23

elixir-stdlib-js

JavaScript
7
star
24

alfred-meteor-atmosphere

Search for Atmosphere Packages with Alfred
7
star
25

alfred-hex-search

Search for Erlang & Elixir packages on Hex with Alfred
6
star
26

restful-js

An opinionated REST framework for Node & Meteor
JavaScript
6
star
27

ocamlish

An OCaml inspired standard library for TypeScript
TypeScript
6
star
28

meteor-graphql-boilerplate

A quick start for using Apollo, Redux, and Meteor
5
star
29

dotfiles

CSS
3
star
30

react-native-navigation-android-example

JavaScript
1
star
31

reason-simple-form

A simple form solution for ReasonML
OCaml
1
star
32

elixir-graphql-issue-54

repro for https://github.com/joshprice/graphql-elixir/issues/54
JavaScript
1
star
33

generator-mgen

Backend for the Meteor Generate CLI
JavaScript
1
star