Remove a pattern

Clear the data of exactly one pattern with remove, leaving every other pattern as it was.

Use this when a rule no longer applies. remove clears the data of exactly the pattern it is given:

const patrun = require('patrun')

const pm = patrun().add({ a: 1 }, 'A').add({ a: 1, b: 1 }, 'AB')

pm.remove({ a: 1, b: 1 })
pm.find({ a: 1, b: 1 }) // → 'A'

Adding a pattern with null or undefined data does the same:

pm.add({ a: 1 }, null)
pm.find({ a: 1 }) // → null

In Go #

Remove, or Add with nil data:

pm := patrun.New()
pm.Add(map[string]string{"a": "1"}, s("A"))
pm.Add(map[string]string{"a": "1", "b": "1"}, s("AB"))

pm.Remove(map[string]string{"a": "1", "b": "1"})
pm.Find(map[string]string{"a": "1", "b": "1"}) // → "A"
pm.Add(map[string]string{"a": "1"}, nil)
pm.Find(map[string]string{"a": "1"}) // → not found

What to watch for #

Removing a pattern that was never added changes nothing. Patterns that share keys with the one removed are not affected. A pattern that add would refuse makes remove throw a TypeError in JavaScript and panic in Go.

This page describes patrun 9.0.0 for JavaScript and 0.4.0 for Go. Edit this page · This page as Markdown