// Copyright (C) 2018 rameshvk. All rights reserved.
// Use of this source code is governed by a MIT-style license
// that can be found in the LICENSE file.

package changes

// Nil represents an empty value. It can be used with Replace or
// Splice to indicate that Before or After is empty. The only
// operation that can be applied is a Replace.  Count and Slice cannot
// be called on it.
var Nil = empty{}

// empty represents an empty value. This should be used instead of nil
// with Replace. The only operation it supports is replacing with
// another value.
type empty struct{}

// Apply can be called on empty but it only supports
// Replace{IsInsert:true} type changes.
func (e empty) Apply(ctx Context, c Change) Value {
	switch c := c.(type) {
	case nil:
		return e
	case Replace:
		if c.IsCreate() {
			return c.After
		}
	}
	return c.(Custom).ApplyTo(ctx, e)
}

Related articles

dot caret_test

// Copyright (C) 2018 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package refs_test import ( "reflect" "testing" "github.com/dotchain/dot/changes" "github.c

dot nw_test

// Copyright (C) 2018 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package nw_test import ( "bytes" "context" "errors" "net/http" "net/http/httptest" "testi

dot image

// Copyright (C) 2019 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package data import ( "github.com/dotchain/dot/changes" "github.com/dotchain/dot/changes/type

dot rank_test

// Copyright (C) 2019 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package crdt_test import ( "testing" "github.com/dotchain/dot/changes/crdt" ) func TestNewR

dot ord_test

// Copyright (C) 2019 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package crdt_test import ( "testing" "github.com/dotchain/dot/changes/crdt" ) func TestIntN

dot generated2

// Generated. DO NOT EDIT. package mystruct import ( "github.com/dotchain/dot/changes" "github.com/dotchain/dot/changes/types" "github.com/dotchain/dot/streams" ) func (my *myStructp) get(key interface{}) changes.Value { switch key { case "b":

dot todo

// Code generated by github.com/tvastar/test/cmd/testmd/testmd.go. DO NOT EDIT. package example import ( "net/http" "sync" "time" "github.com/dotchain/dot" "github.com/dotchain/dot/ops/nw" ) func Server() { // import net/http // import github.

dot callable_test

// Copyright (C) 2019 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package eval_test import ( "testing" "github.com/dotchain/dot/changes" "github.com/dotchain

dot nonblocking

// Copyright (C) 2018 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package sync import ( "context" "sync" "github.com/dotchain/dot/ops" ) // NonBlocking conv

dot row_test

// Copyright (C) 2019 rameshvk. All rights reserved. // Use of this source code is governed by a MIT-style license // that can be found in the LICENSE file. package data_test import ( "testing" "github.com/dotchain/dot/changes" "github.com/dotchain