Skip to content

Instantly share code, notes, and snippets.

View nathggns's full-sized avatar

Nate Higgins nathggns

View GitHub Profile
@markerikson
markerikson / chatsSlice.ts
Last active March 27, 2024 06:37
Nested `createEntityAdapter` example
// Example of using multiple / nested `createEntityAdapter` calls within a single Redux Toolkit slice
interface Message {
id: string;
roomId: string;
text: string;
timestamp: string;
username: string;
}
// Retrieves and recasts the body of an enum
func body<T, U>(of value: inout T) -> U {
return withUnsafePointer(to: &value) {
$0.withMemoryRebound(to: U.self, capacity: 1) {
$0.pointee
}
}
}

Motivation

  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small

Examples

Write in an expression-oriented style, scoping variables as locally as possible:

@jcsrb
jcsrb / header.html
Created August 1, 2013 09:48
mobile first but don't want to show IE8 the mobile version?
<link rel='stylesheet' href='mobile.css' type='text/css' />
<link rel='stylesheet' href='desktop.css' type='text/css' media='(min-width: 961px)' />
<!--[if lt IE 9]>
<link rel='stylesheet' href='desktop.css' type='text/css' />
<![endif]-->