Language | Syntax |
---|---|
Python | lambda x: x + 1 |
JavaScript | x => x + 1 x => { return x + 1; } |
TypeScript | (x: number): number => { return x + 1; } |
Java | x -> x + 1 (int x) -> { return x + 1; } |
Kotlin | { x -> x + 1 } { x: Int -> x + 1 } |
Swift | { $0 + 1 } { x in x + 1 } { (x: Int) -> Int in return x + 1 } |
Rust | |x| x + 1 |
C++ | [](int x) -> int { return x + 1; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void foo(void (*a)(bool, bool), int b, int c, int d, int e) { | |
a(b<c,d>(e)); | |
} | |
template <int, int> int b(int) { return 0; } | |
template <int c, int d> void foo(void (*a)(int), int e) { | |
a(b<c,d>(e)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> | |
#include <atomic> | |
#include <memory> | |
template <class T> class Storage { | |
T* storage; | |
const std::size_t capacity; | |
std::atomic<std::size_t> size; | |
std::atomic<std::size_t> reference_count; | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* You can edit, run, and share this code. | |
* play.kotlinlang.org | |
*/ | |
fun List<String>.iterate(f: (String) -> String) = map(f).joinToString(separator = "") | |
fun main() { | |
val fruits = listOf("apple", "strawberry", "banana") | |
val html = """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
String elem(String tag, String text) { | |
return '<$tag>$text</$tag>'; | |
} | |
String h1(String text) { | |
return elem('h1', text); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias IO<T> = () -> T | |
fun getChar(): IO<Char> { | |
return { | |
'x' | |
} | |
} | |
fun putChar(c: Char): IO<Unit> { | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CFor<A, B, C>(A, B, C); | |
impl<A, B, C> Iterator for CFor<A, B, C> where A: Clone, B: Fn(&A) -> bool, C: Fn(&mut A) { | |
type Item = A; | |
fn next(&mut self) -> Option<A> { | |
if !self.1(&self.0) { | |
return None; | |
} | |
let result = self.0.clone(); | |
self.2(&mut self.0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(m >>= \x -> f x) >>= \x -> g x = m >>= \x -> (f x >>= \x -> g x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void gral_window_warp_cursor(struct gral_window *window, float x, float y) { | |
NSRect window_rect = [[(GralWindow *)window contentView] convertRect:NSMakeRect(x, y, 0, 0) toView:nil]; | |
NSRect screen_rect = [(GralWindow *)window convertRectToScreen:window_rect]; | |
//CGWarpMouseCursorPosition(screen_rect.origin); | |
CGPoint point = [[(GralWindow *)window contentView] convertPoint:NSMakePoint(x, y) toView:nil]; | |
NSRect frame = [(GralWindow *)window frame]; | |
point = CGPointMake(NSMinX(frame) + point.x, NSMaxY(NSScreen.screens[0].frame) - (NSMinY(frame) + point.y)); | |
//CGPoint display_point = CGPointMake(NSMinX(frame) + window_point.x, NSMaxY(NSScreen.screens[0].frame) - (NSMinY(frame) + window_point.y)); | |
CGWarpMouseCursorPosition(point); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <nitro.hpp> | |
using namespace nitro; | |
class DemoAnimation: public Animation { | |
Node* node; | |
public: | |
DemoAnimation(Node* node): node(node) {} | |
bool apply() override { | |
float t = (time % 2000) / 1000.f; |
NewerOlder