(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| // F#'s "pipe-forward" |> operator | |
| // | |
| // Also "Optional-chaining" operators |>! and |>& | |
| // | |
| // And adapters for standard library map/filter/sorted | |
| infix operator |> { precedence 50 associativity left } | |
| infix operator |>! { precedence 50 associativity left } | |
| infix operator |>& { precedence 50 associativity left } | |
| infix operator |>* { precedence 50 associativity left } |
| /* | |
| `arc4random_uniform` is very useful but limited to `UInt32`. | |
| This defines a generic version of `arc4random` for any type | |
| expressible by an integer literal, and extends some numeric | |
| types with a `random` method that mitigates for modulo bias | |
| in the same manner as `arc4random`. | |
| `lower` is inclusive and `upper` is exclusive, thus: | |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| class Event <T:Any> { | |
| var handlers = Array<(T) -> Void>() | |
| func listen(handler: (T) -> Void) { | |
| handlers.append(handler) | |
| } | |
| func emit(object: T) { | |
| for handler in handlers { | |
| handler(object) |
Availability and quality of developer tools are an important factor in the success of a programming language. C/C++ has remained dominant in the systems space in part because of the huge number of tools tailored to these lanaguages. Succesful modern languages have had excellent tool support (Java in particular, Scala, Javascript, etc.). Finally, LLVM has been successful in part because it is much easier to extend than GCC. So far, Rust has done pretty well with developer tools, we have a compiler which produces good quality code in reasonable time, good support for debug symbols which lets us leverage C++/lanaguge agnostic tools such as debuggers, profilers, etc., there are also syntax highlighting, cross-reference, code completion, and documentation tools.
In this document I want to layout what Rust tools exist and where to find them, highlight opportunities for tool developement in the short and long term, and start a discussion about where to focus our time an
| // | |
| // Demonstration of using a channel to receive and dispatch IOHIDManager events using the ChannelZ framework. | |
| // | |
| // Created by Marc Prud'hommeaux on 3/8/15. | |
| // | |
| import Cocoa | |
| import IOKit | |
| import ChannelZ | |
| @NSApplicationMain |
| +(double)distanceBetweenPoint:(CGPoint)pointA andAnotherPoint:(CGPoint)pointB | |
| { | |
| return sqrt((pointA.x - pointB.x)*(pointA.x - pointB.x) + (pointA.y - pointB.y)*(pointA.y - pointB.y)); | |
| } | |
| +(NSArray *)findPointOnTangentOnCircleWithCenter:(CGPoint)center Radius:(double)radius pointOnTangent:(CGPoint)point | |
| { | |
| double dx = center.x - point.x; | |
| double dy = center.y - point.y; | |
| double distance = [EXMathBrain distanceBetweenPoint:center andAnotherPoint:point]; |
| #!/usr/bin/env xcrun swift -i | |
| import Foundation | |
| import Darwin.ncurses | |
| initscr() // Init window. Must be first | |
| cbreak() | |
| noecho() // Don't echo user input | |
| nonl() // Disable newline mode | |
| intrflush(stdscr, true) // Prevent flush |
Because pointers can be ugh
To understand a pointer, let's review "regular" variables first. If you're familiar with a programming language without pointers like JavaScript, this is what you think when you hear "variable".
When declaring a variable by identifier (or name), the variable is synonymous with its value.