openlang

Testing D arrays for a matching entry

with associative arrays this is possible

if (entry in entries) { .. }

how is this done with ordinary arrays? I'd like a validation expression, for example

enforce(candidate in [12,24,48]);

The conversation continues 2

Follow the reasoning
  1. Permalink

    Besides canFind, countUntil is available too and returns the position where the element first appears.

    Remember that D's "in" looks through keys in an associative array, rather than through its values :

    string[string] entries = [
        "left" : "right"
    ];
    
    writeln(("left" in entries) != null); // true
    writeln(("right" in entries) != null); // false

Other sides of the same question

  1. Solc 0.7.0 rejects construction of my struct with a mapping member

    My npm installation provides Solc version 0.7.0. Creating a Struct with a mapping inside emits the message: "Struct containin…

    Replies 2Latest activity solidity
  2. rows.Next said false and the error went nowhere

    Small tool on database/sql returned half a list. No error. The code. Context with a deadline. The deadline fired in the middl…

    Replies 3Latest activity sqlgo
  3. A partial index and a parameter in the WHERE clause

    I'm writing a small job runner in Go for a class project. The setup is pgx v5 through database/sql, Postgres 16 locally, and…

    Replies 10Latest activity sqlgo