% Let's build a binary tree!
Let's build a binary tree of strings in Rust. To recap, each node in a binary tree:
- must have a value
- may or may not have left and/or right children
So we can describe a single node like this:
dashboard "Food": | |
- h1 text: Food | |
- h2 text: By caloric content | |
- 3 columns: | |
- rows: | |
- h3 text: Bananas | |
- pie chart: { | |
"columns": [ | |
["Protein", 5], ["Sugar", 10], ["Other carbs", 40], ["Fat", 1] | |
] |
dashboard "Food": | |
- h1 text: Food | |
- h2 text: By caloric content | |
- 3 columns: | |
- rows: | |
- h3 text: Bananas | |
- pie chart: { | |
"columns": [ | |
["Protein", 5], ["Sugar", 10], ["Other carbs", 40], ["Fat", 1] | |
] |
use std::str::FromStr; | |
fn main () { | |
let mut input = "15 Bear".split(' '); | |
// Need to pull the number and parse it. | |
let number = input.next() | |
// Process Option<&'static str> to Option<int> | |
.and_then(|x| i32::from_str(x).ok() ) | |
.expect("Was not provided a valid number."); | |
// The next token is our animal. |
fn main () { | |
let number: f64 = 20.; | |
// Perform a pipeline of options. | |
let result = Some(number) | |
.map(inverse) // Described below. | |
.map(double) | |
.map(inverse) | |
.and_then(log) // Described below. | |
.map(square) | |
.and_then(sqrt); |
Prelude> (fmap . const) 1 [1..5] | |
[1,1,1,1,1] | |
Prelude> fmap . const 1 [1..5] | |
<interactive>:29:1: error: | |
• Non type-variable argument in the constraint: Num (a1 -> a -> b) | |
(Use FlexibleContexts to permit this) | |
• When checking the inferred type | |
it :: forall b a (f :: * -> *) a1. | |
(Num (a1 -> a -> b), Functor f) => |
[[snippets]] | |
description = "list all files " | |
command = "ls -lah" |
% Let's build a binary tree!
Let's build a binary tree of strings in Rust. To recap, each node in a binary tree:
So we can describe a single node like this:
#!/usr/local/bin/perl | |
package MyAnalyzer { | |
use v5.10; | |
use base qw( Lucy::Analysis::Analyzer ); | |
sub new { | |
my $self = shift->SUPER::new; | |
return $self; | |
} |
https://godbolt.org/g/cmHlPR |
import subprocess | |
def system(cmd): | |
""" | |
Invoke a shell command. | |
:returns: A tuple of output, err message and return code | |
""" | |
ret = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) | |
out, err = ret.communicate() | |
return out, err, ret.returncode |