Skip to content

Learning fp-go question #112

@franchb

Description

@franchb

Hello!

I'm currently in the process of learning fp-go and am aiming to apply functional programming principles in Go. To get hands-on experience, I've taken a straightforward task: rewriting a Go function that initializes a NATS JetStream connection and subsequently creates multiple streams.

Here's the original code for context:

func Fx(lc fx.Lifecycle, natsConn *nats.Conn) FX {
	lc.Append(fx.Hook{OnStart: func(ctx context.Context) error {
		js, err := jetstream.New(natsConn)
		if err != nil {
			return err
		}
		if err = GetCreateEventsStream(ctx, js); err != nil {
			return err
		}
		if err = GetCreateAlertsStream(ctx, js); err != nil {
			return err
		}
		if err = GetCreateDLQStream(ctx, js); err != nil {
			return err
		}
		return nil
	}})
	return FX{}
}

Could someone guide me on the idiomatic way to rewrite this function using fp-go? I'm looking for a functional approach that would align with the paradigms and best practices of the library.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions