Option<T> |
non-Option (T | undefined) |
|
|---|---|---|
| accessing property | userOption.map(user => user.age) |
userNullish?.age |
| calling a method | userOption.map(user => user.fn()) |
userNullish?.fn() |
| providing fallback | ageOption.getOrElse(0) |
ageNullish ?? 0 |
| filter | ageOption.filter(checkIsOddNumber) |
`ageNull |
This file contains hidden or 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 React from "react"; | |
| type NoData = { | |
| _type: "NO_DATA"; | |
| }; | |
| type Data<T> = { | |
| _type: "DATA"; | |
| data: T; | |
| }; |
This file contains hidden or 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
| {-# language FlexibleContexts #-} | |
| {-# language TypeOperators #-} | |
| module DKT where | |
| import Control.Monad (guard) | |
| import Control.Monad.Error.Class (throwError) | |
| import Control.Monad.Trans (lift) | |
| import Control.Monad.Trans.State | |
| import Control.Monad.Trans.Writer |
This file contains hidden or 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
| namespace Maybe | |
| { | |
| public struct Maybe<T> | |
| { | |
| public bool HasValue { get; } | |
| public T Value { get; } | |
| private Maybe(T value) | |
| { | |
| HasValue = true; |
This file contains hidden or 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
| /* | |
| Copy this into the console of any web page that is interactive and doesn't | |
| do hard reloads. You will hear your DOM changes as different pitches of | |
| audio. | |
| I have found this interesting for debugging, but also fun to hear web pages | |
| render like UIs do in movies. | |
| */ | |
| const audioCtx = new (window.AudioContext || window.webkitAudioContext)() |
This file contains hidden or 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 React, { useMemo } from "react"; | |
| import { ApolloClient } from "apollo-client"; | |
| import { ApolloProvider } from "@apollo/react-hooks"; | |
| import { HttpLink } from "apollo-link-http"; | |
| import { InMemoryCache } from "apollo-cache-inmemory"; | |
| import { useWeb3React } from "@web3-react/core"; | |
| const CHAIN_IDS_TO_NAMES = { | |
| 1: "mainnet", |
This file contains hidden or 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
| for node in node1 node2 node3;do | |
| multipass launch -n $node | |
| done | |
| # Init cluster on node1 | |
| multipass exec node1 -- bash -c "curl -sfL https://get.k3s.io | sh -" | |
| # Get node1's IP | |
| IP=$(multipass info node1 | grep IPv4 | awk '{print $2}') |
Spoilers for Advent of Code 2019 follow.
Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.
This describes a simple function. There seems to be an oversight in the problem statement that modules with very low mass have a negative fuel requirement. I'm going to assume that's not right, and that instead of integer subtraction, we want natural number subtraction (sometimes called "monus"). In Unison, we can use the Nat type instead of integers, so we don't have to consider negatives. The subtraction operation is called drop: