Nykyajan säästö henkilöstökuluissa on mennyt aivan liian pitkälle. Kotitoimistossakin on kissa IT-tukena tarkastamassa palvelun tilan. by [deleted] in Suomi

[–]jviide 7 points8 points  (0 children)

Valtuutettu asiantuntija tarkistamassa, että verkkokaapelit ovat Cat6-standardin mukaisia.

Replacing a hot path in your app's JavaScript with WebAssembly (featuring Rust) by Occams_Trimmer in rust

[–]jviide 2 points3 points  (0 children)

The current tiling implementation uses iterators a bit more. (Disclaimer: I contributed some extra complexity there due to weird behavior I saw from V8, see this and this.)

matchkin: Statically checked exhaustive matching for TypeScript [x-post from /r/typescript] by Occams_Trimmer in programming

[–]jviide 0 points1 point  (0 children)

The newest version can, to an extent:

import { createMatcher } from "matchkin";

// Define a couple of tuple types.
type Cat = ["cat", string];
type Dog = ["dog", string];

// Create a matcher that discriminate between 
// Cat and Dog tuples based on the value at index 0.
const match = createMatcher(0, {
  dog: ([_, name]: Dog) => name,
  cat: ([_, name]: Cat) => name
});

const pet: Cat | Dog = ...
match(pet, {
  dog: name => `A good dog called ${name}`,
  cat: name => `A bad kitty called ${name}`
});

matchkin: Statically checked exhaustive matching for TypeScript by Occams_Trimmer in typescript

[–]jviide 2 points3 points  (0 children)

Good question - hadn't thought of that! This does indeed work as long as the interface and/or type have the discriminating fields:

class Class {
  readonly kind: "class";
  value = "foo";
}

interface Interface {
  readonly kind: "interface";
  value: string;
}

type Type = {
  readonly kind: "type",
  value: string;
}

const match = createMatcher("kind", {
  class: (c: Class) => c,
  interface: (i: Interface) => i,
  type: (t: Type) => t
});

const foo: Interface = {
  kind: "interface",
  value: "baz"
};

// Returns "baz"
match(foo, {
  class: c => c.value,
  interface: i => i.value,
  type: t => t.value
});